Skip to content

Commit

Permalink
some fix and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Sep 12, 2024
1 parent 06fd7f8 commit 51ddf52
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 47 deletions.
9 changes: 8 additions & 1 deletion src/config/ConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
91 changes: 47 additions & 44 deletions src/utils/Assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,28 @@ 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?
* @param providerUrl the provider URL
* @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'
Expand All @@ -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,
Expand All @@ -180,7 +179,7 @@ export async function createAsset(
const nftParamsAsset: NftCreateData = {
name,
symbol,
templateIndex,
templateIndex: 1,
tokenURI: 'aaa',
transferable: true,
owner: account
Expand All @@ -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
}
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
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.createNftWithDatatokenWithFixedRate(
nftParamsAsset,
datatokenParams,
fixedPriceParams
)
} catch (err) {
console.log('ERROR creating NFT bundle', err)
return null
}

const trxReceipt = await bundleNFT.wait()
Expand Down
4 changes: 2 additions & 2 deletions test/integration/PublishFlows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 51ddf52

Please sign in to comment.