Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Aug 10, 2023
1 parent 095de14 commit 9a1850f
Show file tree
Hide file tree
Showing 7 changed files with 2,768 additions and 2,930 deletions.
5,202 changes: 2,632 additions & 2,570 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"dependencies": {
"@elastic/elasticsearch": "7.12.0",
"@golevelup/nestjs-rabbitmq": "3.4.0",
"@multiversx/sdk-core": "11.2.0",
"@multiversx/sdk-native-auth-server": "1.0.6",
"@multiversx/sdk-core": "12.6.1",
"@multiversx/sdk-native-auth-server": "1.0.7",
"@multiversx/sdk-nestjs": "0.4.16",
"@multiversx/sdk-network-providers": "^1.2.1",
"@nestjs/apollo": "^10.1.7",
Expand Down Expand Up @@ -76,7 +76,7 @@
"helmet": "4.4.1",
"jwks-rsa": "2.0.3",
"moment": "^2.29.4",
"mongoose": "6.9.0",
"mongoose": "6.11.5",
"mysql2": "2.2.5",
"nest-winston": "1.8.0",
"object-hash": "2.2.0",
Expand Down
95 changes: 22 additions & 73 deletions src/modules/assets/assets-transaction.service.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
import {
Address,
AddressValue,
BytesValue,
ContractFunction,
TokenPayment,
U64Value,
} from '@multiversx/sdk-core';
import { Address, AddressValue, BytesValue, ContractFunction, TokenPayment, U64Value } from '@multiversx/sdk-core';
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { MxApiService, getSmartContract } from 'src/common';
import { mxConfig, gas } from 'src/config';
import {
getCollectionAndNonceFromIdentifier,
timestampToEpochAndRound,
} from 'src/utils/helpers';
import { getCollectionAndNonceFromIdentifier, timestampToEpochAndRound } from 'src/utils/helpers';
import '../../utils/extensions';
import { nominateVal } from '../../utils/formatters';
import { FileContent } from '../ipfs/file.content';
import { PinataService } from '../ipfs/pinata.service';
import { S3Service } from '../s3/s3.service';
import BigNumber from 'bignumber.js';
import { TransactionNode } from '../common/transaction';
import {
UpdateQuantityRequest,
CreateNftRequest,
TransferNftRequest,
CreateNftWithMultipleFilesRequest,
} from './models/requests';
import { UpdateQuantityRequest, CreateNftRequest, TransferNftRequest, CreateNftWithMultipleFilesRequest } from './models/requests';
import { generateCacheKeyFromParams } from 'src/utils/generate-cache-key';
import { FileUpload } from 'graphql-upload';
import { MxStats } from 'src/common/services/mx-communication/models/mx-stats.model';
Expand All @@ -42,36 +27,22 @@ export class AssetsTransactionService {
private redisCacheService: RedisCacheService,
) {}

async updateQuantity(
ownerAddress: string,
request: UpdateQuantityRequest,
): Promise<TransactionNode> {
const { collection, nonce } = getCollectionAndNonceFromIdentifier(
request.identifier,
);
async updateQuantity(ownerAddress: string, request: UpdateQuantityRequest): Promise<TransactionNode> {
const { collection, nonce } = getCollectionAndNonceFromIdentifier(request.identifier);
const contract = getSmartContract(request.updateQuantityRoleAddress);
const transaction = contract.call({
func: new ContractFunction(request.functionName),
value: TokenPayment.egldFromAmount(0),
args: [
BytesValue.fromUTF8(collection),
BytesValue.fromHex(nonce),
new U64Value(new BigNumber(request.quantity)),
],
args: [BytesValue.fromUTF8(collection), BytesValue.fromHex(nonce), new U64Value(new BigNumber(request.quantity))],
gasLimit: gas.addBurnQuantity,
chainID: mxConfig.chainID,
caller: new Address(ownerAddress),
});
return transaction.toPlainObject(new Address(ownerAddress));
return transaction.toPlainObject();
}

async burnQuantity(
ownerAddress: string,
request: UpdateQuantityRequest,
): Promise<TransactionNode> {
const [nft, mxStats] = await Promise.all([
this.mxApiService.getNftByIdentifier(request.identifier),
this.getOrSetAproximateMxStats(),
]);
async burnQuantity(ownerAddress: string, request: UpdateQuantityRequest): Promise<TransactionNode> {
const [nft, mxStats] = await Promise.all([this.mxApiService.getNftByIdentifier(request.identifier), this.getOrSetAproximateMxStats()]);

if (!nft) {
throw new NotFoundException('NFT not found');
Expand Down Expand Up @@ -99,10 +70,7 @@ export class AssetsTransactionService {
);
}

async createNftWithMultipleFiles(
ownerAddress: string,
request: CreateNftWithMultipleFilesRequest,
): Promise<TransactionNode> {
async createNftWithMultipleFiles(ownerAddress: string, request: CreateNftWithMultipleFilesRequest): Promise<TransactionNode> {
let uploadFilePromises = [];
for (const file of request.files) {
uploadFilePromises.push(this.uploadFileToPinata(file));
Expand All @@ -112,22 +80,14 @@ export class AssetsTransactionService {
return this.getCreateNftTransaction(ownerAddress, request, filesToIpfs);
}

async createNft(
ownerAddress: string,
request: CreateNftRequest,
): Promise<TransactionNode> {
async createNft(ownerAddress: string, request: CreateNftRequest): Promise<TransactionNode> {
const fileData = await this.uploadFileToPinata(request.file);

return this.getCreateNftTransaction(ownerAddress, request, [fileData]);
}

async transferNft(
ownerAddress: string,
transferRequest: TransferNftRequest,
): Promise<TransactionNode> {
const { collection, nonce } = getCollectionAndNonceFromIdentifier(
transferRequest.identifier,
);
async transferNft(ownerAddress: string, transferRequest: TransferNftRequest): Promise<TransactionNode> {
const { collection, nonce } = getCollectionAndNonceFromIdentifier(transferRequest.identifier);
const contract = getSmartContract(ownerAddress);
const transaction = contract.call({
func: new ContractFunction('ESDTNFTTransfer'),
Expand All @@ -140,12 +100,10 @@ export class AssetsTransactionService {
],
gasLimit: gas.nftTransfer,
chainID: mxConfig.chainID,
caller: new Address(ownerAddress),
});
let response = transaction.toPlainObject(new Address(ownerAddress));
response.gasLimit = Math.max(
mxConfig.transferMinCost + response.data.length * mxConfig.pricePerByte,
gas.nftTransfer,
);
let response = transaction.toPlainObject();
response.gasLimit = Math.max(mxConfig.transferMinCost + response.data.length * mxConfig.pricePerByte, gas.nftTransfer);
return {
...response,
chainID: mxConfig.chainID,
Expand All @@ -157,9 +115,7 @@ export class AssetsTransactionService {
request: CreateNftRequest | CreateNftWithMultipleFilesRequest,
filesData: UploadToIpfsResult[],
) {
const assetMetadata = await this.uploadFileMetadata(
request.attributes.description,
);
const assetMetadata = await this.uploadFileMetadata(request.attributes.description);
const attributes = `tags:${request.attributes.tags};metadata:${assetMetadata.hash}`;
const contract = getSmartContract(ownerAddress);
const transaction = contract.call({
Expand All @@ -168,8 +124,9 @@ export class AssetsTransactionService {
args: this.getCreateNftsArgs(request, filesData, attributes),
gasLimit: gas.nftCreate,
chainID: mxConfig.chainID,
caller: new Address(ownerAddress),
});
let response = transaction.toPlainObject(new Address(ownerAddress));
let response = transaction.toPlainObject();

return {
...response,
Expand All @@ -195,11 +152,7 @@ export class AssetsTransactionService {
return fileData;
}

private getCreateNftsArgs(
request: CreateNftWithMultipleFilesRequest | CreateNftRequest,
filesToIpfs: any[],
attributes: string,
) {
private getCreateNftsArgs(request: CreateNftWithMultipleFilesRequest | CreateNftRequest, filesToIpfs: any[], attributes: string) {
const args = [
BytesValue.fromUTF8(request.collection),
new U64Value(new BigNumber(request.quantity)),
Expand All @@ -218,11 +171,7 @@ export class AssetsTransactionService {
try {
const cacheKey = this.getApproximateMxStatsCacheKey();
const getMxStats = () => this.mxApiService.getMxStats();
return this.redisCacheService.getOrSet(
cacheKey,
getMxStats,
Constants.oneDay(),
);
return this.redisCacheService.getOrSet(cacheKey, getMxStats, Constants.oneDay());
} catch (error) {
this.logger.error('An error occurred while getting mx stats', {
path: `${AssetsTransactionService.name}.${this.getOrSetAproximateMxStats.name}`,
Expand Down
36 changes: 24 additions & 12 deletions src/modules/auctions/nft-marketplace.abi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Constants, RedisCacheService } from '@multiversx/sdk-nestjs';
export class NftMarketplaceAbiService {
private readonly parser: ResultsParser;

private contract = new ContractLoader(MarketplaceUtils.commonMarketplaceAbiPath, MarketplaceUtils.abiInterface);
private contract = new ContractLoader(MarketplaceUtils.commonMarketplaceAbiPath, MarketplaceUtils.abiInterface);

constructor(
Expand Down Expand Up @@ -76,8 +77,9 @@ export class NftMarketplaceAbiService {
args: this.getCreateAuctionArgs(args, marketplace.address),
gasLimit: gas.startAuction,
chainID: mxConfig.chainID,
caller: new Address(ownerAddress),
});
return createAuctionTx.toPlainObject(new Address(ownerAddress));
return createAuctionTx.toPlainObject();
}

async bid(ownerAddress: string, request: BidRequest): Promise<TransactionNode> {
Expand All @@ -98,8 +100,9 @@ export class NftMarketplaceAbiService {
args: [new U64Value(new BigNumber(auction.marketplaceAuctionId))],
gasLimit: gas.withdraw,
chainID: mxConfig.chainID,
caller: new Address(ownerAddress),
});
return withdraw.toPlainObject(new Address(ownerAddress));
return withdraw.toPlainObject();
}

async createOffer(ownerAddress: string, request: CreateOfferRequest): Promise<TransactionNode> {
Expand All @@ -119,13 +122,15 @@ export class NftMarketplaceAbiService {
if (request.paymentToken !== mxConfig.egld) {
return intermediateInteraction
.withSingleESDTTransfer(TokenPayment.fungibleFromBigInteger(request.paymentToken, new BigNumber(request.paymentAmount)))
.withSender(new Address(ownerAddress))
.buildTransaction()
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}
return intermediateInteraction
.withValue(TokenPayment.egldFromBigInteger(request.paymentAmount))
.withSender(new Address(ownerAddress))
.buildTransaction()
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}

private async getGenericOfferInteraction(
Expand Down Expand Up @@ -153,8 +158,9 @@ export class NftMarketplaceAbiService {
.withValue(TokenPayment.egldFromAmount(0))
.withChainID(mxConfig.chainID)
.withGasLimit(gas.withdraw)
.withSender(new Address(ownerAddress))
.buildTransaction()
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}

async acceptOffer(ownerAddress: string, request: AcceptOfferRequest): Promise<TransactionNode> {
Expand Down Expand Up @@ -200,8 +206,9 @@ export class NftMarketplaceAbiService {
)
.withChainID(mxConfig.chainID)
.withGasLimit(gas.withdraw)
.withSender(new Address(ownerAddress))
.buildTransaction()
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}

private async acceptOfferAndWithdrawAuction(ownerAddress: string, offerId: number, auctionId: number): Promise<TransactionNode> {
Expand All @@ -226,8 +233,9 @@ export class NftMarketplaceAbiService {
.withValue(TokenPayment.egldFromAmount(0))
.withChainID(mxConfig.chainID)
.withGasLimit(gas.withdraw)
.withSender(new Address(ownerAddress))
.buildTransaction()
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}

async endAuction(ownerAddress: string, auctionId: number): Promise<TransactionNode> {
Expand All @@ -239,9 +247,10 @@ export class NftMarketplaceAbiService {
args: [new U64Value(new BigNumber(auction.marketplaceAuctionId))],
gasLimit: gas.endAuction,
chainID: mxConfig.chainID,
caller: new Address(ownerAddress),
});

return endAuction.toPlainObject(new Address(ownerAddress));
return endAuction.toPlainObject();
}

async buySft(ownerAddress: string, request: BuySftRequest): Promise<TransactionNode> {
Expand Down Expand Up @@ -416,8 +425,9 @@ export class NftMarketplaceAbiService {
args: [new U64Value(new BigNumber(marketplaceAuctionId)), BytesValue.fromUTF8(collection), BytesValue.fromHex(nonce)],
gasLimit: gas.bid,
chainID: mxConfig.chainID,
caller: new Address(ownerAddress),
})
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}

private async bidWithEsdt(
Expand All @@ -433,8 +443,9 @@ export class NftMarketplaceAbiService {
.withSingleESDTTransfer(TokenPayment.fungibleFromBigInteger(request.paymentTokenIdentifier, new BigNumber(request.price)))
.withChainID(mxConfig.chainID)
.withGasLimit(gas.bid)
.withSender(new Address(ownerAddress))
.buildTransaction()
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}

private async buySftWithEgld(
Expand All @@ -450,8 +461,9 @@ export class NftMarketplaceAbiService {
args: this.getBuySftArguments(request, marketplaceAuctionId),
gasLimit: gas.buySft,
chainID: mxConfig.chainID,
caller: new Address(ownerAddress),
})
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}

private async buySftWithEsdt(
Expand All @@ -466,6 +478,6 @@ export class NftMarketplaceAbiService {
.withChainID(mxConfig.chainID)
.withGasLimit(gas.buySft)
.buildTransaction()
.toPlainObject(new Address(ownerAddress));
.toPlainObject();
}
}
Loading

0 comments on commit 9a1850f

Please sign in to comment.