1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

remove duplicate file + fix import

This commit is contained in:
paulo-ocean 2024-10-01 10:30:25 +01:00
parent 8d579de47a
commit c80d69ec32
2 changed files with 1 additions and 88 deletions

View File

@ -12,7 +12,7 @@ import { SmartContract } from './SmartContract'
import {
calculateActiveTemplateIndex,
getOceanArtifactsAdressesByChainId
} from '../utils/Asset'
} from '../utils/Assets'
export class Nft extends SmartContract {
getDefaultAbi() {

View File

@ -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<number> {
// 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
}