Skip to content

Commit

Permalink
feat: add getNFTTradesByToken. (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz committed Aug 12, 2024
1 parent 57fdd34 commit 4434f6e
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/slimy-berries-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/evm-api': patch
'moralis': patch
---

Added a new method to the EVM API: `getNFTTradesByToken`.
3 changes: 2 additions & 1 deletion packages/common/evmUtils/generator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
"getDefiPositionsSummary",
"getWalletProfitabilitySummary",
"getWalletProfitability",
"getTopProfitableWalletPerToken"
"getTopProfitableWalletPerToken",
"getNFTTradesByToken"
]
}
}
Expand Down
28 changes: 28 additions & 0 deletions packages/common/evmUtils/src/generated/client/abstractClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GetNFTTradesOperation, GetNFTTradesOperationRequest, GetNFTTradesOperationRequestJSON } from '../operations/GetNFTTradesOperation';
import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCollection';
import { GetNFTTradesByTokenOperation, GetNFTTradesByTokenOperationRequest, GetNFTTradesByTokenOperationRequestJSON } from '../operations/GetNFTTradesByTokenOperation';
import { GetNFTContractSalePricesOperation, GetNFTContractSalePricesOperationRequest, GetNFTContractSalePricesOperationRequestJSON } from '../operations/GetNFTContractSalePricesOperation';
import { EvmSoldPrice, EvmSoldPriceJSON } from '../types/EvmSoldPrice';
import { GetNFTSalePricesOperation, GetNFTSalePricesOperationRequest, GetNFTSalePricesOperationRequestJSON } from '../operations/GetNFTSalePricesOperation';
Expand Down Expand Up @@ -214,6 +215,33 @@ export abstract class AbstractClient {
EvmTradeCollection,
EvmTradeCollectionJSON
>(GetNFTTradesOperation),
/**
* @description Get trades of NFTs for a given contract and token ID.
* @param request Request with parameters.
* @param {Object} request.address The address of the NFT contract
* @param {String} request.tokenId The token ID of the NFT contract
* @param {Object} [request.chain] The chain to query (optional)
* @param {Number} [request.fromBlock] The minimum block number from which to get the transfers
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used. (optional)
* @param {Number} [request.toBlock] The block number to get the trades from (optional)
* @param {Date} [request.fromDate] The start date from which to get the transfers (format in seconds or datestring accepted by momentjs)
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used. (optional)
* @param {Date} [request.toDate] The end date from which to get the transfers (format in seconds or datestring accepted by momentjs)
* * Provide the param 'to_block' or 'to_date'
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used. (optional)
* @param {String} [request.cursor] The cursor returned in the previous response (used for getting the next page). (optional)
* @param {Number} [request.limit] The desired page size of the result. (optional)
* @param {Boolean} [request.nftMetadata] Include the NFT Metadata of the NFT Token (optional)
* @returns {Object} Response for the request.
*/
getNFTTradesByToken: this.createEndpoint<
GetNFTTradesByTokenOperationRequest,
GetNFTTradesByTokenOperationRequestJSON,
EvmTradeCollection,
EvmTradeCollectionJSON
>(GetNFTTradesByTokenOperation),
/**
* @description Get the sold price for an NFT contract for the last x days (only trades paid in ETH).
* @param request Request with parameters.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCollection';

// request parameters:
// - chain ($ref: #/components/schemas/nftTradesChainList)
// - from_block ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/1/schema)
// - to_block ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/2/schema)
// - from_date ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/3/schema)
// - to_date ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/4/schema)
// - cursor ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/5/schema)
// - limit ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/6/schema)
// - nft_metadata ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/7/schema)
// - address ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/8/schema)
// - token_id ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/9/schema)

export interface GetNFTTradesByTokenOperationRequest {
/**
* @description The chain to query
*/
readonly chain?: EvmChainInput | EvmChain;
/**
* @description The minimum block number from which to get the transfers
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used.
*/
readonly fromBlock?: number;
/**
* @description The block number to get the trades from
*/
readonly toBlock?: number;
/**
* @description The start date from which to get the transfers (format in seconds or datestring accepted by momentjs)
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used.
*/
readonly fromDate?: Date;
/**
* @description The end date from which to get the transfers (format in seconds or datestring accepted by momentjs)
* * Provide the param 'to_block' or 'to_date'
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used.
*/
readonly toDate?: Date;
/**
* @description The cursor returned in the previous response (used for getting the next page).
*/
readonly cursor?: string;
/**
* @description The desired page size of the result.
*/
readonly limit?: number;
/**
* @description Include the NFT Metadata of the NFT Token
*/
readonly nftMetadata?: boolean;
/**
* @description The address of the NFT contract
*/
readonly address: EvmAddressInput | EvmAddress;
/**
* @description The token ID of the NFT contract
*/
readonly tokenId: string;
}

export interface GetNFTTradesByTokenOperationRequestJSON {
readonly chain?: EvmChainJSON;
readonly from_block?: number;
readonly to_block?: string;
readonly from_date?: string;
readonly to_date?: string;
readonly cursor?: string;
readonly limit?: number;
readonly nft_metadata?: boolean;
readonly address: EvmAddressJSON;
readonly token_id: string;
}

export type GetNFTTradesByTokenOperationResponse = EvmTradeCollection;
export type GetNFTTradesByTokenOperationResponseJSON = EvmTradeCollectionJSON;

export const GetNFTTradesByTokenOperation = {
operationId: "getNFTTradesByToken",
groupName: "nft",
httpMethod: "get",
routePattern: "/nft/{address}/{token_id}/trades",
parameterNames: ["chain","from_block","to_block","from_date","to_date","cursor","limit","nft_metadata","address","token_id"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmTradeCollectionJSON): EvmTradeCollection {
return EvmTradeCollection.fromJSON(json);
},

serializeRequest(request: GetNFTTradesByTokenOperationRequest): GetNFTTradesByTokenOperationRequestJSON {
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
const fromBlock = request.fromBlock;
const toBlock = request.toBlock;
const fromDate = request.fromDate;
const toDate = request.toDate;
const cursor = request.cursor;
const limit = request.limit;
const nftMetadata = request.nftMetadata;
const address = EvmAddress.create(request.address);
const tokenId = request.tokenId;
return {
chain: chain ? chain.toJSON() : undefined,
from_block: fromBlock,
to_block: toBlock !== undefined ? String(toBlock) : undefined,
from_date: fromDate !== undefined ? fromDate.toISOString() : undefined,
to_date: toDate !== undefined ? toDate.toISOString() : undefined,
cursor: cursor,
limit: limit,
nft_metadata: nftMetadata,
address: address.toJSON(),
token_id: tokenId,
};
},

}
1 change: 1 addition & 0 deletions packages/common/evmUtils/src/generated/operations/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './GetNFTTradesOperation';
export * from './GetNFTTradesByTokenOperation';
export * from './GetNFTContractSalePricesOperation';
export * from './GetNFTSalePricesOperation';
export * from './GetMultipleTokenPricesOperation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GetNFTTradesOperation } from './GetNFTTradesOperation';
import { GetNFTTradesByTokenOperation } from './GetNFTTradesByTokenOperation';
import { GetNFTContractSalePricesOperation } from './GetNFTContractSalePricesOperation';
import { GetNFTSalePricesOperation } from './GetNFTSalePricesOperation';
import { GetMultipleTokenPricesOperation } from './GetMultipleTokenPricesOperation';
Expand Down Expand Up @@ -32,6 +33,7 @@ import { GetTopProfitableWalletPerTokenOperation } from './GetTopProfitableWalle

export const operations = [
GetNFTTradesOperation,
GetNFTTradesByTokenOperation,
GetNFTContractSalePricesOperation,
GetNFTSalePricesOperation,
GetMultipleTokenPricesOperation,
Expand Down
Loading

1 comment on commit 4434f6e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 20%
20.6% (61/296) 20.48% (17/83) 19.04% (12/63)
auth Coverage: 89%
92.45% (98/106) 83.33% (20/24) 86.66% (26/30)
evm-api Coverage: 76%
77.58% (90/116) 66.66% (6/9) 68.29% (56/82)
common-aptos-utils Coverage: 4%
4.56% (151/3306) 4.49% (25/556) 5.53% (45/813)
common-evm-utils Coverage: 54%
54.81% (2231/4070) 15.92% (172/1080) 36.19% (489/1351)
sol-api Coverage: 97%
97.56% (40/41) 66.66% (6/9) 93.75% (15/16)
common-sol-utils Coverage: 64%
65.42% (229/350) 41.86% (18/43) 50.89% (57/112)
common-streams-utils Coverage: 90%
90.73% (1204/1327) 73.63% (363/493) 82.07% (444/541)
streams Coverage: 91%
90.54% (603/666) 72.34% (68/94) 90.97% (131/144)

Please sign in to comment.