Skip to content

Commit

Permalink
Merge pull request #1843 from oceanprotocol/issue-1841-pub-flow
Browse files Browse the repository at this point in the history
Issue 1841 pub flow - createAsset Fn
  • Loading branch information
paulo-ocean authored Oct 4, 2024
2 parents fdfe741 + ea7562f commit 7b340ad
Show file tree
Hide file tree
Showing 12 changed files with 487 additions and 102 deletions.
4 changes: 4 additions & 0 deletions src/@types/Datatoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface DatatokenCreateParams {
cap: string
name?: string
symbol?: string
filesObject?: any // file object for template 4
accessListFactory?: string // access list factory address
allowAccessList?: string // Allow List Contract (if any)
denyAccessList?: string // Deny List Contract (if any)
}

export interface ConsumeMarketFee {
Expand Down
4 changes: 4 additions & 0 deletions src/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,8 @@ export class Config {
DFRewards?: string
DFStrategyV1?: string
veFeeEstimate?: string

// is confidential evm
confidentialEVM?: boolean
accessListFactory?: string
}
32 changes: 29 additions & 3 deletions src/config/ConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ export const configHelperNetworks: Config[] = [
}
]

export const KNOWN_CONFIDENTIAL_EVMS = [
23294, // oasis_sapphire
23295 // oasis_sapphire_testnet
]

export class ConfigHelper {
/* Load contract addresses from env ADDRESS_FILE (generated by ocean-contracts) */
public getAddressesFromEnv(network: string, customAddresses?: any): Partial<Config> {
Expand All @@ -200,7 +205,8 @@ export class ConfigHelper {
veDelegationProxy,
DFRewards,
DFStrategyV1,
veFeeEstimate
veFeeEstimate,
AccessListFactory
} = customAddresses[network]
configAddresses = {
nftFactoryAddress: ERC721Factory,
Expand All @@ -218,6 +224,7 @@ export class ConfigHelper {
DFRewards,
DFStrategyV1,
veFeeEstimate,
accessListFactory: AccessListFactory,
...(process.env.AQUARIUS_URL && { metadataCacheUri: process.env.AQUARIUS_URL }),
...(process.env.PROVIDER_URL && { providerUri: process.env.PROVIDER_URL })
}
Expand All @@ -239,7 +246,8 @@ export class ConfigHelper {
veDelegationProxy,
DFRewards,
DFStrategyV1,
veFeeEstimate
veFeeEstimate,
AccessListFactory
} = DefaultContractsAddresses[network]
configAddresses = {
nftFactoryAddress: ERC721Factory,
Expand All @@ -257,6 +265,7 @@ export class ConfigHelper {
DFRewards,
DFStrategyV1,
veFeeEstimate,
accessListFactory: AccessListFactory,
...(process.env.AQUARIUS_URL && { metadataCacheUri: process.env.AQUARIUS_URL }),
...(process.env.PROVIDER_URL && { providerUri: process.env.PROVIDER_URL })
}
Expand All @@ -273,6 +282,7 @@ export class ConfigHelper {
*/
public getConfig(network: string | number, infuraProjectId?: string): Config {
const filterBy = typeof network === 'string' ? 'network' : 'chainId'

let config = configHelperNetworks.find((c) => c[filterBy] === network)

if (!config) {
Expand All @@ -292,7 +302,23 @@ export class ConfigHelper {
console.log(e)
addresses = null
}
const contractAddressesConfig = this.getAddressesFromEnv(config.network, addresses)

let contractAddressesConfig = this.getAddressesFromEnv(config.network, addresses)
// check oasis network name typos on addresses.json
if (!contractAddressesConfig && KNOWN_CONFIDENTIAL_EVMS.includes(config.chainId)) {
contractAddressesConfig = this.getAddressesFromEnv(
config.network.replace('sapph', 'saph'),
addresses
)
}
config.confidentialEVM =
filterBy === 'chainId'
? KNOWN_CONFIDENTIAL_EVMS.includes(Number(network))
: network.toString().includes('oasis_sap')
if (config.confidentialEVM) {
config.accessListFactory = contractAddressesConfig.accessListFactory
}

config = { ...config, ...contractAddressesConfig }

const nodeUri = infuraProjectId
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/NFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SmartContract } from './SmartContract'
import {
calculateActiveTemplateIndex,
getOceanArtifactsAdressesByChainId
} from '../utils/Asset'
} from '../utils/Assets'

export class Nft extends SmartContract {
getDefaultAbi() {
Expand Down
35 changes: 27 additions & 8 deletions src/contracts/NFTFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber } from 'ethers'
import { BigNumber, ethers } from 'ethers'
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
import {
generateDtName,
Expand Down Expand Up @@ -580,20 +580,39 @@ export class NftFactory extends SmartContractWithAddress {
}
}

// common stuff for other templates
const addresses = [
dtParams.minter,
dtParams.paymentCollector,
dtParams.mpFeeAddress,
dtParams.feeToken
]

if (dtParams.filesObject) {
// template 4 only, ignored for others
if (dtParams.accessListFactory) {
addresses.push(dtParams.accessListFactory)
}
if (dtParams.allowAccessList) {
addresses.push(dtParams.allowAccessList)
}

if (dtParams.denyAccessList) {
addresses.push(dtParams.denyAccessList)
}
}

return {
templateIndex: dtParams.templateIndex,
strings: [dtParams.name || name, dtParams.symbol || symbol],
addresses: [
dtParams.minter,
dtParams.paymentCollector,
dtParams.mpFeeAddress,
dtParams.feeToken
],
addresses,
uints: [
await this.amountToUnits(null, dtParams.cap, 18),
await this.amountToUnits(null, dtParams.feeAmount, feeTokenDecimals)
],
bytess: []
bytess: dtParams.filesObject
? [ethers.utils.toUtf8Bytes(JSON.stringify(dtParams.filesObject))]
: []
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export class Provider {
)) + 1
).toString()

const signature = await this.signProviderRequest(signer, did + nonce)
const signature = await this.signProviderRequest(signer, did + nonce) // did + nonce
let consumeUrl = downloadUrl
consumeUrl += `?fileIndex=${fileIndex}`
consumeUrl += `&documentId=${did}`
Expand Down
87 changes: 0 additions & 87 deletions src/utils/Asset.ts

This file was deleted.

Loading

0 comments on commit 7b340ad

Please sign in to comment.