mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
some fix and refactor
This commit is contained in:
parent
06fd7f8e18
commit
51ddf52d58
@ -300,8 +300,15 @@ 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.replaceAll('sapp', 'sap'),
|
||||
addresses
|
||||
)
|
||||
}
|
||||
config.confidentialEVM =
|
||||
filterBy === 'chainId'
|
||||
? KNOWN_CONFIDENTIAL_EVMS.includes(Number(network))
|
||||
|
@ -118,7 +118,7 @@ export async function calculateActiveTemplateIndex(
|
||||
* @param name asset name
|
||||
* @param symbol asse symbol
|
||||
* @param owner owner address
|
||||
* @param assetUrl asset url
|
||||
* @param assetUrl asset url, if present and confidential evm, add it to token create params
|
||||
* @param templateIDorAddress either template address or id
|
||||
* @param ddo ddo
|
||||
* @param encryptDDO encrypt or not?
|
||||
@ -126,22 +126,20 @@ export async function calculateActiveTemplateIndex(
|
||||
* @param providerFeeToken the provider fee token
|
||||
* @param nftContractAddress the nft contract address
|
||||
* @param aquariusInstance aquarius, could be node instance url
|
||||
* @param filesObject if present and confidential evm, add it to token create params
|
||||
* @returns ddo id as string
|
||||
*/
|
||||
export async function createAsset(
|
||||
name: string,
|
||||
symbol: string,
|
||||
owner: Signer,
|
||||
assetUrl: any,
|
||||
assetUrl: any, // files object
|
||||
templateIDorAddress: string | number, // If string, it's template address , otherwise, it's templateId
|
||||
ddo: any,
|
||||
encryptDDO: boolean = true, // default is true
|
||||
providerUrl: string,
|
||||
providerFeeToken: string,
|
||||
nftContractAddress: string, // addresses.ERC721Factory,
|
||||
aquariusInstance: Aquarius,
|
||||
filesObject?: any
|
||||
nftContractAddress?: string // addresses.ERC721Factory,
|
||||
): Promise<string> {
|
||||
const isAddress = typeof templateIDorAddress === 'string'
|
||||
const isTemplateIndex = typeof templateIDorAddress === 'number'
|
||||
@ -152,8 +150,9 @@ export async function createAsset(
|
||||
|
||||
const config = new ConfigHelper().getConfig(parseInt(String(chainID)))
|
||||
|
||||
// This function does not consider the fact the template could be disabled
|
||||
// let templateIndex = await calculateTemplateIndex(chainID, template)
|
||||
if (!nftContractAddress) {
|
||||
nftContractAddress = config.nftFactoryAddress
|
||||
}
|
||||
|
||||
let templateIndex = await calculateActiveTemplateIndex(
|
||||
owner,
|
||||
@ -180,7 +179,7 @@ export async function createAsset(
|
||||
const nftParamsAsset: NftCreateData = {
|
||||
name,
|
||||
symbol,
|
||||
templateIndex,
|
||||
templateIndex: 1,
|
||||
tokenURI: 'aaa',
|
||||
transferable: true,
|
||||
owner: account
|
||||
@ -196,46 +195,50 @@ export async function createAsset(
|
||||
}
|
||||
|
||||
// include fileObject in the DT constructor
|
||||
if (config.confidentialEVM && templateIndex === 4) {
|
||||
datatokenParams.filesObject = filesObject
|
||||
if (config.confidentialEVM) {
|
||||
datatokenParams.filesObject = assetUrl
|
||||
}
|
||||
|
||||
let bundleNFT
|
||||
|
||||
if (!ddo.stats?.price?.value) {
|
||||
bundleNFT = await nftFactory.createNftWithDatatoken(nftParamsAsset, datatokenParams)
|
||||
} else if (ddo.stats?.price?.value === '0') {
|
||||
const dispenserParams: DispenserCreationParams = {
|
||||
dispenserAddress: config.dispenserAddress,
|
||||
maxTokens: '1',
|
||||
maxBalance: '100000000',
|
||||
withMint: true,
|
||||
allowedSwapper: ZERO_ADDRESS
|
||||
try {
|
||||
if (!ddo.stats?.price?.value) {
|
||||
bundleNFT = await nftFactory.createNftWithDatatoken(nftParamsAsset, datatokenParams)
|
||||
} else if (ddo.stats?.price?.value === '0') {
|
||||
const dispenserParams: DispenserCreationParams = {
|
||||
dispenserAddress: config.dispenserAddress,
|
||||
maxTokens: '1',
|
||||
maxBalance: '100000000',
|
||||
withMint: true,
|
||||
allowedSwapper: ZERO_ADDRESS
|
||||
}
|
||||
bundleNFT = await nftFactory.createNftWithDatatokenWithDispenser(
|
||||
nftParamsAsset,
|
||||
datatokenParams,
|
||||
dispenserParams
|
||||
)
|
||||
} else {
|
||||
// fixed price
|
||||
const fixedPriceParams: FreCreationParams = {
|
||||
fixedRateAddress: config.fixedRateExchangeAddress,
|
||||
baseTokenAddress: config.oceanTokenAddress,
|
||||
owner: account,
|
||||
marketFeeCollector: account,
|
||||
baseTokenDecimals: 18,
|
||||
datatokenDecimals: 18,
|
||||
fixedRate: ddo.stats.price.value,
|
||||
marketFee: '0',
|
||||
allowedConsumer: account,
|
||||
withMint: true
|
||||
}
|
||||
bundleNFT = await nftFactory.createNftWithDatatokenWithFixedRate(
|
||||
nftParamsAsset,
|
||||
datatokenParams,
|
||||
fixedPriceParams
|
||||
)
|
||||
}
|
||||
bundleNFT = await nftFactory.createNftWithDatatokenWithDispenser(
|
||||
nftParamsAsset,
|
||||
datatokenParams,
|
||||
dispenserParams
|
||||
)
|
||||
} else {
|
||||
// fixed price
|
||||
const fixedPriceParams: FreCreationParams = {
|
||||
fixedRateAddress: config.fixedRateExchangeAddress,
|
||||
baseTokenAddress: config.oceanTokenAddress,
|
||||
owner: account,
|
||||
marketFeeCollector: account,
|
||||
baseTokenDecimals: 18,
|
||||
datatokenDecimals: 18,
|
||||
fixedRate: ddo.stats.price.value,
|
||||
marketFee: '0',
|
||||
allowedConsumer: account,
|
||||
withMint: true
|
||||
}
|
||||
bundleNFT = await nftFactory.createNftWithDatatokenWithFixedRate(
|
||||
nftParamsAsset,
|
||||
datatokenParams,
|
||||
fixedPriceParams
|
||||
)
|
||||
} catch (err) {
|
||||
console.log('ERROR creating NFT bundle', err)
|
||||
return null
|
||||
}
|
||||
|
||||
const trxReceipt = await bundleNFT.wait()
|
||||
|
@ -212,8 +212,8 @@ describe('Publish tests', async () => {
|
||||
true, // encrypted ddo
|
||||
providerUrl,
|
||||
ZERO_ADDRESS, // provider fee token
|
||||
addresses.ERC721Factory, // nft template factory
|
||||
aquarius
|
||||
aquarius,
|
||||
addresses.ERC721Factory // nft template factory
|
||||
)
|
||||
|
||||
console.log('Published asset, ddo id:', asset)
|
||||
|
Loading…
x
Reference in New Issue
Block a user