mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
wip... refactroing..
This commit is contained in:
parent
6bca7d6c56
commit
f5166bd08c
15
package-lock.json
generated
15
package-lock.json
generated
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -179,4 +179,7 @@ export class Config {
|
||||
DFRewards?: string
|
||||
DFStrategyV1?: string
|
||||
veFeeEstimate?: string
|
||||
|
||||
// is confidential evm
|
||||
confidentialEVM?: boolean
|
||||
}
|
||||
|
@ -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<Config> {
|
||||
@ -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
|
||||
|
@ -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))]
|
||||
: []
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<number> {
|
||||
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<string> {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user