diff --git a/package-lock.json b/package-lock.json index eca735ff..e836e09f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.3.3", "license": "Apache-2.0", "dependencies": { - "@oceanprotocol/contracts": "^2.0.3", + "@oceanprotocol/contracts": "^2.2.0", "cross-fetch": "^4.0.0", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", @@ -2971,9 +2971,10 @@ } }, "node_modules/@oceanprotocol/contracts": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-2.0.3.tgz", - "integrity": "sha512-D2YtlsgmhBuSmF/Ue8zMWPtXNiB4zgW09NjUQzvDFrloUo0a7yC8r8L84LrVniw+0Nmly/PhLcdm8i018yc34g==" + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-2.2.0.tgz", + "integrity": "sha512-QhewXdtTebycRSZEdkAdvJkSMMnGZyxldlw2eX4VOJto8wymyNdxuhjL/tiaZ5xO7SS5BqURricx9170hfh2kQ==", + "license": "Apache-2.0" }, "node_modules/@octokit/auth-token": { "version": "3.0.3", @@ -19726,9 +19727,9 @@ } }, "@oceanprotocol/contracts": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-2.0.3.tgz", - "integrity": "sha512-D2YtlsgmhBuSmF/Ue8zMWPtXNiB4zgW09NjUQzvDFrloUo0a7yC8r8L84LrVniw+0Nmly/PhLcdm8i018yc34g==" + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-2.2.0.tgz", + "integrity": "sha512-QhewXdtTebycRSZEdkAdvJkSMMnGZyxldlw2eX4VOJto8wymyNdxuhjL/tiaZ5xO7SS5BqURricx9170hfh2kQ==" }, "@octokit/auth-token": { "version": "3.0.3", diff --git a/package.json b/package.json index 9b4f1eba..c49b03aa 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "web3": "^1.8.0" }, "dependencies": { - "@oceanprotocol/contracts": "^2.0.3", + "@oceanprotocol/contracts": "^2.2.0", "cross-fetch": "^4.0.0", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", diff --git a/src/config/Config.ts b/src/config/Config.ts index 5b5b3eeb..904c6cb9 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -179,4 +179,7 @@ export class Config { DFRewards?: string DFStrategyV1?: string veFeeEstimate?: string + + // is confidential evm + confidentialEVM?: boolean } diff --git a/src/config/ConfigHelper.ts b/src/config/ConfigHelper.ts index ad76a14f..6bcc9d11 100644 --- a/src/config/ConfigHelper.ts +++ b/src/config/ConfigHelper.ts @@ -154,7 +154,8 @@ export const configHelperNetworks: Config[] = [ nodeUri: 'https://sapphire.oasis.io', subgraphUri: 'https://v4.subgraph.sapphire-mainnet.oceanprotocol.com/', explorerUri: 'https://explorer.oasis.io/mainnet/sapphire/', - gasFeeMultiplier: 1 + gasFeeMultiplier: 1, + confidentialEVM: true }, { ...configHelperNetworksBase, @@ -168,6 +169,10 @@ export const configHelperNetworks: Config[] = [ } ] +export const KNOWN_CONFIDENTIAL_EVMS = { + names: ['asis_saphire_testnet', 'oasis_saphire'], + chainIds: [23295, 23294] +} export class ConfigHelper { /* Load contract addresses from env ADDRESS_FILE (generated by ocean-contracts) */ public getAddressesFromEnv(network: string, customAddresses?: any): Partial { @@ -283,6 +288,16 @@ export class ConfigHelper { addresses = null } const contractAddressesConfig = this.getAddressesFromEnv(config.network, addresses) + // network name + if (filterBy === 'network') { + config.confidentialEVM = KNOWN_CONFIDENTIAL_EVMS.names.includes( + network.toString().toLowerCase() + ) + // chain id + } else { + config.confidentialEVM = KNOWN_CONFIDENTIAL_EVMS.chainIds.includes(Number(network)) + } + config = { ...config, ...contractAddressesConfig } const nodeUri = infuraProjectId diff --git a/src/contracts/NFTFactory.ts b/src/contracts/NFTFactory.ts index 09cb6004..3cd16f2f 100644 --- a/src/contracts/NFTFactory.ts +++ b/src/contracts/NFTFactory.ts @@ -583,10 +583,9 @@ export class NftFactory extends SmartContractWithAddress { await this.amountToUnits(null, dtParams.cap, 18), await this.amountToUnits(null, dtParams.feeAmount, feeTokenDecimals) ], - bytess: - dtParams.templateIndex === 4 - ? [ethers.utils.toUtf8Bytes(JSON.stringify(dtParams.filesObject))] - : [] + bytess: dtParams.filesObject + ? [ethers.utils.toUtf8Bytes(JSON.stringify(dtParams.filesObject))] + : [] } } diff --git a/src/utils/Assets.ts b/src/utils/Assets.ts index dca60e29..f8972b7e 100644 --- a/src/utils/Assets.ts +++ b/src/utils/Assets.ts @@ -22,8 +22,61 @@ import { } from '../../src' import { hexlify } from 'ethers/lib/utils' import { createHash } from 'crypto' +import fs from 'fs' +import addresses from '@oceanprotocol/contracts/addresses/address.json' assert { type: 'json' } -const VALID_TEMPLATE_INDEXES = [1, 2, 4] +// template address OR templateId +export function isConfidentialEVM(network: string | number): boolean { + const config = new ConfigHelper().getConfig(network) + return config && config.confidentialEVM +} + +/** + * 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 addresses + } catch (error) { + return addresses + } +} + +/** + * Get the artifacts address from the address.json file, for the given chain + * either from the env or from the ocean-contracts dir, safer than above, because sometimes the network name + * is mispeled, best example "optimism_sepolia" vs "optimism-sepolia" + * @returns data or null + */ +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 +} + +export async function calculateTemplateIndex(chainID: number): Promise { + const artifacts = await getOceanArtifactsAdressesByChainId(chainID) + return -1 +} /** * * @param name asset name @@ -47,7 +100,7 @@ export async function createAsset( symbol: string, owner: Signer, assetUrl: any, - templateIndex: number, + template: string | number, // If string, it's template address , otherwise, it's templateId ddo: any, encryptDDO: boolean = true, // default is true providerUrl: string, @@ -60,10 +113,11 @@ export async function createAsset( // fixedRateAddress?: string, // baseTokenAddress?: string // ocean token? ): Promise { - if (!VALID_TEMPLATE_INDEXES.includes(templateIndex)) { - throw new Error('Invalid template index: ' + templateIndex) + const isAddress = typeof template === 'string' + const isTemplateIndex = typeof template === 'number' + if (!isAddress && !isTemplateIndex) { + throw new Error('Invalid template! Must be a "number" or a "string"') } - const chainID = (await owner.provider.getNetwork()).chainId const config = new ConfigHelper().getConfig(parseInt(String(chainID))) @@ -96,7 +150,7 @@ export async function createAsset( } // include fileObject in the DT constructor - if (templateIndex === 4) { + if (config.confidentialEVM) { datatokenParams.filesObject = filesObject } @@ -149,10 +203,8 @@ export async function createAsset( assetUrl.datatokenAddress = datatokenAddressAsset assetUrl.nftAddress = nftAddress // TODO if template 4 no need to encrypt it?? - if (templateIndex !== 4) { + if (config.confidentialEVM) { ddo.services[0].files = await ProviderInstance.encrypt(assetUrl, chainID, providerUrl) - } else { - ddo.services[0].files = assetUrl } ddo.services[0].datatokenAddress = datatokenAddressAsset