mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
few more changes, use config
This commit is contained in:
parent
17603be1bb
commit
6bca7d6c56
@ -10,7 +10,7 @@ export interface DatatokenCreateParams {
|
|||||||
cap: string
|
cap: string
|
||||||
name?: string
|
name?: string
|
||||||
symbol?: string
|
symbol?: string
|
||||||
fileObject?: any // file object for template 4
|
filesObject?: any // file object for template 4
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConsumeMarketFee {
|
export interface ConsumeMarketFee {
|
||||||
|
@ -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 ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||||
import {
|
import {
|
||||||
generateDtName,
|
generateDtName,
|
||||||
@ -583,7 +583,10 @@ export class NftFactory extends SmartContractWithAddress {
|
|||||||
await this.amountToUnits(null, dtParams.cap, 18),
|
await this.amountToUnits(null, dtParams.cap, 18),
|
||||||
await this.amountToUnits(null, dtParams.feeAmount, feeTokenDecimals)
|
await this.amountToUnits(null, dtParams.feeAmount, feeTokenDecimals)
|
||||||
],
|
],
|
||||||
bytess: []
|
bytess:
|
||||||
|
dtParams.templateIndex === 4
|
||||||
|
? [ethers.utils.toUtf8Bytes(JSON.stringify(dtParams.filesObject))]
|
||||||
|
: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ import {
|
|||||||
// ProviderFees,
|
// ProviderFees,
|
||||||
getEventFromTx,
|
getEventFromTx,
|
||||||
DispenserCreationParams,
|
DispenserCreationParams,
|
||||||
FreCreationParams
|
FreCreationParams,
|
||||||
|
ConfigHelper
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
import { hexlify } from 'ethers/lib/utils'
|
import { hexlify } from 'ethers/lib/utils'
|
||||||
import { createHash } from 'crypto'
|
import { createHash } from 'crypto'
|
||||||
@ -53,25 +54,29 @@ export async function createAsset(
|
|||||||
providerFeeToken: string,
|
providerFeeToken: string,
|
||||||
nftContractAddress: string, // addresses.ERC721Factory,
|
nftContractAddress: string, // addresses.ERC721Factory,
|
||||||
aquariusInstance: Aquarius,
|
aquariusInstance: Aquarius,
|
||||||
filesObject: any,
|
filesObject?: any
|
||||||
// fixed rate
|
// fixed rate
|
||||||
dispenserAddress?: string,
|
// dispenserAddress?: string,
|
||||||
fixedRateAddress?: string,
|
// fixedRateAddress?: string,
|
||||||
baseTokenAddress?
|
// baseTokenAddress?: string // ocean token?
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
if (!VALID_TEMPLATE_INDEXES.includes(templateIndex)) {
|
if (!VALID_TEMPLATE_INDEXES.includes(templateIndex)) {
|
||||||
throw new Error('Invalid template index: ' + templateIndex)
|
throw new Error('Invalid template index: ' + templateIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
const chain = (await owner.provider.getNetwork()).chainId
|
const chainID = (await owner.provider.getNetwork()).chainId
|
||||||
|
|
||||||
const nft = new Nft(owner, chain)
|
const config = new ConfigHelper().getConfig(parseInt(String(chainID)))
|
||||||
|
|
||||||
|
const nft = new Nft(owner, chainID)
|
||||||
|
|
||||||
const nftFactory = new NftFactory(nftContractAddress, owner)
|
const nftFactory = new NftFactory(nftContractAddress, owner)
|
||||||
|
|
||||||
|
// get nft owner
|
||||||
const account = await owner.getAddress()
|
const account = await owner.getAddress()
|
||||||
|
|
||||||
ddo.chainId = parseInt(chain.toString(10))
|
// from hex to number format
|
||||||
|
ddo.chainId = parseInt(chainID.toString(10))
|
||||||
const nftParamsAsset: NftCreateData = {
|
const nftParamsAsset: NftCreateData = {
|
||||||
name,
|
name,
|
||||||
symbol,
|
symbol,
|
||||||
@ -85,14 +90,14 @@ export async function createAsset(
|
|||||||
cap: '100000',
|
cap: '100000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
paymentCollector: account,
|
paymentCollector: account,
|
||||||
feeToken: providerFeeToken,
|
feeToken: providerFeeToken || config.oceanTokenAddress,
|
||||||
minter: account,
|
minter: account,
|
||||||
mpFeeAddress: ZERO_ADDRESS
|
mpFeeAddress: ZERO_ADDRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
// include fileObject in the DT constructor
|
// include fileObject in the DT constructor
|
||||||
if (templateIndex === 4) {
|
if (templateIndex === 4) {
|
||||||
datatokenParams.fileObject = filesObject
|
datatokenParams.filesObject = filesObject
|
||||||
}
|
}
|
||||||
|
|
||||||
let bundleNFT
|
let bundleNFT
|
||||||
@ -101,7 +106,7 @@ export async function createAsset(
|
|||||||
bundleNFT = await nftFactory.createNftWithDatatoken(nftParamsAsset, datatokenParams)
|
bundleNFT = await nftFactory.createNftWithDatatoken(nftParamsAsset, datatokenParams)
|
||||||
} else if (ddo.stats?.price?.value === '0') {
|
} else if (ddo.stats?.price?.value === '0') {
|
||||||
const dispenserParams: DispenserCreationParams = {
|
const dispenserParams: DispenserCreationParams = {
|
||||||
dispenserAddress,
|
dispenserAddress: config.dispenserAddress,
|
||||||
maxTokens: '1',
|
maxTokens: '1',
|
||||||
maxBalance: '100000000',
|
maxBalance: '100000000',
|
||||||
withMint: true,
|
withMint: true,
|
||||||
@ -115,8 +120,8 @@ export async function createAsset(
|
|||||||
} else {
|
} else {
|
||||||
// fixed price
|
// fixed price
|
||||||
const fixedPriceParams: FreCreationParams = {
|
const fixedPriceParams: FreCreationParams = {
|
||||||
fixedRateAddress,
|
fixedRateAddress: config.fixedRateExchangeAddress,
|
||||||
baseTokenAddress,
|
baseTokenAddress: config.oceanTokenAddress,
|
||||||
owner: account,
|
owner: account,
|
||||||
marketFeeCollector: account,
|
marketFeeCollector: account,
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -143,22 +148,24 @@ export async function createAsset(
|
|||||||
// create the files encrypted string
|
// create the files encrypted string
|
||||||
assetUrl.datatokenAddress = datatokenAddressAsset
|
assetUrl.datatokenAddress = datatokenAddressAsset
|
||||||
assetUrl.nftAddress = nftAddress
|
assetUrl.nftAddress = nftAddress
|
||||||
// TODO if template 4??
|
// TODO if template 4 no need to encrypt it??
|
||||||
if (templateIndex !== 4) {
|
if (templateIndex !== 4) {
|
||||||
ddo.services[0].files = await ProviderInstance.encrypt(assetUrl, chain, providerUrl)
|
ddo.services[0].files = await ProviderInstance.encrypt(assetUrl, chainID, providerUrl)
|
||||||
|
} else {
|
||||||
|
ddo.services[0].files = assetUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
ddo.services[0].datatokenAddress = datatokenAddressAsset
|
ddo.services[0].datatokenAddress = datatokenAddressAsset
|
||||||
ddo.services[0].serviceEndpoint = providerUrl
|
ddo.services[0].serviceEndpoint = providerUrl
|
||||||
|
|
||||||
ddo.nftAddress = nftAddress
|
ddo.nftAddress = nftAddress
|
||||||
ddo.id = 'did:op:' + SHA256(ethers.utils.getAddress(nftAddress) + chain.toString(10))
|
ddo.id = 'did:op:' + SHA256(ethers.utils.getAddress(nftAddress) + chainID.toString(10))
|
||||||
|
|
||||||
let metadata
|
let metadata
|
||||||
let metadataHash
|
let metadataHash
|
||||||
let flags
|
let flags
|
||||||
if (encryptDDO) {
|
if (encryptDDO) {
|
||||||
metadata = await ProviderInstance.encrypt(ddo, chain, providerUrl)
|
metadata = await ProviderInstance.encrypt(ddo, chainID, providerUrl)
|
||||||
const validateResult = await aquariusInstance.validate(ddo)
|
const validateResult = await aquariusInstance.validate(ddo)
|
||||||
metadataHash = validateResult.hash
|
metadataHash = validateResult.hash
|
||||||
flags = 2
|
flags = 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user