From c80d69ec3235b14dfc4cb5a26ad6f330aa1f6db1 Mon Sep 17 00:00:00 2001 From: paulo-ocean Date: Tue, 1 Oct 2024 10:30:25 +0100 Subject: [PATCH] remove duplicate file + fix import --- src/contracts/NFT.ts | 2 +- src/utils/Asset.ts | 87 -------------------------------------------- 2 files changed, 1 insertion(+), 88 deletions(-) delete mode 100644 src/utils/Asset.ts diff --git a/src/contracts/NFT.ts b/src/contracts/NFT.ts index a951192a..4fb0afae 100644 --- a/src/contracts/NFT.ts +++ b/src/contracts/NFT.ts @@ -12,7 +12,7 @@ import { SmartContract } from './SmartContract' import { calculateActiveTemplateIndex, getOceanArtifactsAdressesByChainId -} from '../utils/Asset' +} from '../utils/Assets' export class Nft extends SmartContract { getDefaultAbi() { diff --git a/src/utils/Asset.ts b/src/utils/Asset.ts deleted file mode 100644 index 9eb8e24e..00000000 --- a/src/utils/Asset.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { ethers, Signer } from 'ethers' - -import { NftFactory } from '../contracts/NFTFactory' -// eslint-disable-next-line import/no-named-default -import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json' -import fs from 'fs' -// eslint-disable-next-line import/no-named-default -import { default as addrs } from '@oceanprotocol/contracts/addresses/address.json' - -/** - * Get the artifacts address from the address.json file - * either from the env or from the ocean-contracts dir - * @returns data or null - */ -export function getOceanArtifactsAdresses(): any { - try { - if (process.env.ADDRESS_FILE) { - // eslint-disable-next-line security/detect-non-literal-fs-filename - const data = fs.readFileSync(process.env.ADDRESS_FILE, 'utf8') - return JSON.parse(data) - } - return addrs - } catch (error) { - return addrs - } -} - -export function getOceanArtifactsAdressesByChainId(chain: number): any { - try { - // eslint-disable-next-line security/detect-non-literal-fs-filename - const data = getOceanArtifactsAdresses() - if (data) { - const networks = Object.keys(data) - for (const network of networks) { - if (data[network].chainId === chain) { - return data[network] - } - } - } - } catch (error) { - console.error(error) - } - return null -} - -/** - * Use this function to accurately calculate the template index, and also checking if the template is active - * @param owner the signer account - * @param nftContractAddress the nft contract address, usually artifactsAddresses.ERC721Factory - * @param template the template ID or template address (from smart contract getId() function) - * @returns index of the template on the list - */ -export async function calculateActiveTemplateIndex( - owner: Signer, - nftContractAddress: string, // addresses.ERC721Factory, - template: string | number -): Promise { - // is an ID number? - const isTemplateID = typeof template === 'number' - - const factoryERC721 = new NftFactory(nftContractAddress, owner) - const currentTokenCount = await factoryERC721.getCurrentTokenTemplateCount() - for (let i = 1; i <= currentTokenCount; i++) { - const tokenTemplate = await factoryERC721.getTokenTemplate(i) - - const erc20Template = new ethers.Contract( - tokenTemplate.templateAddress, - ERC20Template.abi, - owner - ) - - // check for ID - if (isTemplateID) { - const id = await erc20Template.connect(owner).getId() - if (tokenTemplate.isActive && id.toString() === template.toString()) { - return i - } - } else if ( - tokenTemplate.isActive && - tokenTemplate.templateAddress === template.toString() - ) { - return i - } - } - // if nothing is found it returns -1 - return -1 -}