diff --git a/package.json b/package.json index 06f7cc6..d38417a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-ts", - "version": "3.0.19", + "version": "3.0.20", "description": "Nevermined Node", "main": "main.ts", "scripts": { @@ -131,5 +131,6 @@ ] }, "author": "Nevermined", - "license": "Apache-2.0" + "license": "Apache-2.0", + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/access/access.controller.ts b/src/access/access.controller.ts index 156b666..be4beda 100644 --- a/src/access/access.controller.ts +++ b/src/access/access.controller.ts @@ -48,6 +48,7 @@ import { AssetResult, NeverminedService } from '../shared/nevermined/nvm.service import { TransferDto } from './dto/transfer' import { UploadDto } from './dto/upload' import { UploadResult } from './dto/upload-result' +import { formatUnits } from 'viem' export enum UploadBackends { IPFS = 'ipfs', @@ -254,14 +255,31 @@ export class AccessController { if (!this.backendService.isBackendEnabled()) { Logger.log(`NVM Backend not enabled, skipping tracking transaction in the database`) } else { - const assetPrice = this.nvmService.getAssetPrice(service) / 10n ** BigInt(4) + const assetPrice = this.nvmService.getAssetPrice(service).getTotalPrice() + const erc20TokenAddress = + this.nvmService.getAssetPrice(service)?.getTokenAddress() || + this.nvmService.getNevermined().utils.token.getAddress() + + let currency: string + let decimals: number + if (erc20TokenAddress === ZeroAddress) { + currency = 'ETH' + decimals = 18 + } else { + const erc20 = await this.nvmService.getNevermined().contracts.loadErc20(erc20TokenAddress) + currency = await erc20.symbol() + decimals = await erc20.decimals() + } + + const priceHighestDenomination = +formatUnits(assetPrice, decimals) + const assetTx: AssetTransaction = { assetDid: did.getDid(), assetOwner: subscriptionDDO.proof.creator, assetConsumer: transferData.nftReceiver, txType: 'Mint', - price: (Number(assetPrice) / 100).toString(), - currency: 'USDC', + price: priceHighestDenomination.toString(), + currency: currency, paymentType: 'Crypto', txHash: JSON.stringify(txs), metadata: '', diff --git a/src/shared/nevermined/nvm.service.ts b/src/shared/nevermined/nvm.service.ts index 1dbf255..07e94fb 100644 --- a/src/shared/nevermined/nvm.service.ts +++ b/src/shared/nevermined/nvm.service.ts @@ -9,6 +9,7 @@ import { StreamableFile, } from '@nestjs/common' import { + AssetPrice, DDO, DDOError, DDOServiceNotFoundError, @@ -472,10 +473,10 @@ export class NeverminedService { return Number(duration) || 0 } - public getAssetPrice(service: ServiceCommon): bigint { + public getAssetPrice(service: ServiceCommon): AssetPrice { const assetPrice = DDO.getAssetPriceFromService(service) - if (assetPrice) return assetPrice.getTotalPrice() + if (assetPrice) return assetPrice throw new DDOError(`No price found for asset ${service.index}`) }