From 9d022b31d5d5b60cf131828442d675a3fe91fa3c Mon Sep 17 00:00:00 2001 From: paulo-ocean Date: Tue, 5 Nov 2024 09:45:14 +0000 Subject: [PATCH] fix approve if needed only + v2 additional assets --- src/commands.ts | 12 +++++++++--- src/helpers.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index d2c50c0..08d5d8f 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -411,6 +411,10 @@ export class Commands { " with additional datasets:" + (!additionalDatasets ? "none" : additionalDatasets[0].documentId) ); + if(additionalDatasets!==null) { + console.log('Adding additional datasets to dataset, according to C2D V2 specs') + assets.push(additionalDatasets) + } const output: ComputeOutput = { metadataUri: await getMetadataURI() @@ -420,12 +424,14 @@ export class Commands { providerURI, this.signer, computeEnv.id, - assets[0], + assets, // assets[0] // only c2d v1, algo, null, - additionalDatasets, - output + // additionalDatasets, only c2d v1 + output, + computeEnv.free ? true : false // ); + if (computeJobs && computeJobs[0]) { const { jobId, agreementId } = computeJobs[0]; console.log("Compute started. JobID: " + jobId); diff --git a/src/helpers.ts b/src/helpers.ts index 4e38a11..b6aa98c 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -130,6 +130,7 @@ export async function createAsset( datatokenParams ); } else if (ddo?.stats?.price?.value === "0") { + const dispenserParams: DispenserCreationParams = { dispenserAddress: config.dispenserAddress, maxTokens: "1", @@ -137,7 +138,6 @@ export async function createAsset( withMint: true, allowedSwapper: ZERO_ADDRESS, }; - bundleNFT = await nftFactory.createNftWithDatatokenWithDispenser( nftParamsAsset, datatokenParams, @@ -299,7 +299,10 @@ export async function handleComputeOrder( - have validOrder and providerFees -> then order is valid but providerFees are not valid, we need to call reuseOrder and pay only providerFees - no validOrder -> we need to call startOrder, to pay 1 DT & providerFees */ - if (order.providerFee && order.providerFee.providerFeeAmount) { + const hasProviderFees = order.providerFee && order.providerFee.providerFeeAmount + // no need to approve if it is 0 + if (hasProviderFees && Number(order.providerFee.providerFeeAmount) > 0) { + await approveWei( payerAccount, config, @@ -308,6 +311,7 @@ export async function handleComputeOrder( asset.services[0].datatokenAddress, order.providerFee.providerFeeAmount ); + } if (order.validOrder) { if (!order.providerFee) return order.validOrder;