Skip to content

Commit

Permalink
feat: expose sales endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHoong committed Jun 3, 2024
1 parent e7cac79 commit c2f2e58
Show file tree
Hide file tree
Showing 18 changed files with 1,012 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/slimy-carrots-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/common-evm-utils': minor
'@moralisweb3/evm-api': minor
---

Expose `getNFTContractSalePrices` & `getNFTSalePrices`
4 changes: 3 additions & 1 deletion packages/common/evmUtils/generator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
"resolveAddressToDomain",
"getTopCryptoCurrenciesByMarketCap",
"getTopCryptoCurrenciesByTradingVolume",
"getWalletHistory"
"getWalletHistory",
"getNFTSalePrices",
"getNFTContractSalePrices"
]
}
}
Expand Down
34 changes: 34 additions & 0 deletions packages/common/evmUtils/src/generated/client/abstractClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { GetNFTTradesOperation, GetNFTTradesOperationRequest, GetNFTTradesOperationRequestJSON } from '../operations/GetNFTTradesOperation';
import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCollection';
import { GetNFTContractSalePricesOperation, GetNFTContractSalePricesOperationRequest, GetNFTContractSalePricesOperationRequestJSON } from '../operations/GetNFTContractSalePricesOperation';
import { EvmSoldPrice, EvmSoldPriceJSON } from '../types/EvmSoldPrice';
import { GetNFTSalePricesOperation, GetNFTSalePricesOperationRequest, GetNFTSalePricesOperationRequestJSON } from '../operations/GetNFTSalePricesOperation';
import { GetMultipleTokenPricesOperation, GetMultipleTokenPricesOperationRequest, GetMultipleTokenPricesOperationRequestJSON } from '../operations/GetMultipleTokenPricesOperation';
import { EvmErc20Price, EvmErc20PriceJSON } from '../types/EvmErc20Price';
import { EvmGetMultipleTokenPricesDto, EvmGetMultipleTokenPricesDtoInput, EvmGetMultipleTokenPricesDtoJSON } from '../types/EvmGetMultipleTokenPricesDto';
Expand Down Expand Up @@ -196,6 +199,37 @@ export abstract class AbstractClient {
EvmTradeCollection,
EvmTradeCollectionJSON
>(GetNFTTradesOperation),
/**
* @description Get the sold price for an NFT contract for the last x days (only trades paid in ETH).
* @param request Request with parameters.
* @param {Object} request.address The address of the NFT collection
* @param {Object} [request.chain] The chain to query (optional)
* @param {Number} [request.days] The number of days to look back to find the lowest price
* If not provided 7 days will be the default (optional)
* @returns {Object} Response for the request.
*/
getNFTContractSalePrices: this.createEndpoint<
GetNFTContractSalePricesOperationRequest,
GetNFTContractSalePricesOperationRequestJSON,
EvmSoldPrice,
EvmSoldPriceJSON
>(GetNFTContractSalePricesOperation),
/**
* @description Get the sold price for an NFT token for the last x days (only trades paid in ETH).
* @param request Request with parameters.
* @param {Object} request.address The address of the NFT collection
* @param {String} request.tokenId The token id of the NFT collection
* @param {Object} [request.chain] The chain to query (optional)
* @param {Number} [request.days] The number of days to look back to find the lowest price
* If not provided 7 days will be the default (optional)
* @returns {Object} Response for the request.
*/
getNFTSalePrices: this.createEndpoint<
GetNFTSalePricesOperationRequest,
GetNFTSalePricesOperationRequestJSON,
EvmSoldPrice,
EvmSoldPriceJSON
>(GetNFTSalePricesOperation),
/**
* @description Get the stats for a nft collection address.
* @param request Request with parameters.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { EvmSoldPrice, EvmSoldPriceJSON } from '../types/EvmSoldPrice';

// request parameters:
// - chain ($ref: #/components/schemas/nftTradesChainList)
// - days ($ref: #/paths/~1nft~1{address}~1price/get/parameters/1/schema)
// - address ($ref: #/paths/~1nft~1{address}~1price/get/parameters/2/schema)

export interface GetNFTContractSalePricesOperationRequest {
/**
* @description The chain to query
*/
readonly chain?: EvmChainInput | EvmChain;
/**
* @description The number of days to look back to find the lowest price
* If not provided 7 days will be the default
*/
readonly days?: number;
/**
* @description The address of the NFT collection
*/
readonly address: EvmAddressInput | EvmAddress;
}

export interface GetNFTContractSalePricesOperationRequestJSON {
readonly chain?: EvmChainJSON;
readonly days?: number;
readonly address: EvmAddressJSON;
}

export type GetNFTContractSalePricesOperationResponse = EvmSoldPrice;
export type GetNFTContractSalePricesOperationResponseJSON = EvmSoldPriceJSON;

export const GetNFTContractSalePricesOperation = {
operationId: "getNFTContractSalePrices",
groupName: "nft",
httpMethod: "get",
routePattern: "/nft/{address}/price",
parameterNames: ["chain","days","address"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmSoldPriceJSON): EvmSoldPrice {
return EvmSoldPrice.fromJSON(json);
},

serializeRequest(request: GetNFTContractSalePricesOperationRequest): GetNFTContractSalePricesOperationRequestJSON {
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
const days = request.days;
const address = EvmAddress.create(request.address);
return {
chain: chain ? chain.toJSON() : undefined,
days: days,
address: address.toJSON(),
};
},

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { EvmSoldPrice, EvmSoldPriceJSON } from '../types/EvmSoldPrice';

// request parameters:
// - chain ($ref: #/components/schemas/nftTradesChainList)
// - days ($ref: #/paths/~1nft~1{address}~1{token_id}~1price/get/parameters/1/schema)
// - address ($ref: #/paths/~1nft~1{address}~1{token_id}~1price/get/parameters/2/schema)
// - token_id ($ref: #/paths/~1nft~1{address}~1{token_id}~1price/get/parameters/3/schema)

export interface GetNFTSalePricesOperationRequest {
/**
* @description The chain to query
*/
readonly chain?: EvmChainInput | EvmChain;
/**
* @description The number of days to look back to find the lowest price
* If not provided 7 days will be the default
*/
readonly days?: number;
/**
* @description The address of the NFT collection
*/
readonly address: EvmAddressInput | EvmAddress;
/**
* @description The token id of the NFT collection
*/
readonly tokenId: string;
}

export interface GetNFTSalePricesOperationRequestJSON {
readonly chain?: EvmChainJSON;
readonly days?: number;
readonly address: EvmAddressJSON;
readonly token_id: string;
}

export type GetNFTSalePricesOperationResponse = EvmSoldPrice;
export type GetNFTSalePricesOperationResponseJSON = EvmSoldPriceJSON;

export const GetNFTSalePricesOperation = {
operationId: "getNFTSalePrices",
groupName: "nft",
httpMethod: "get",
routePattern: "/nft/{address}/{token_id}/price",
parameterNames: ["chain","days","address","token_id"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmSoldPriceJSON): EvmSoldPrice {
return EvmSoldPrice.fromJSON(json);
},

serializeRequest(request: GetNFTSalePricesOperationRequest): GetNFTSalePricesOperationRequestJSON {
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
const days = request.days;
const address = EvmAddress.create(request.address);
const tokenId = request.tokenId;
return {
chain: chain ? chain.toJSON() : undefined,
days: days,
address: address.toJSON(),
token_id: tokenId,
};
},

}
2 changes: 2 additions & 0 deletions packages/common/evmUtils/src/generated/operations/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export * from './GetNFTTradesOperation';
export * from './GetNFTContractSalePricesOperation';
export * from './GetNFTSalePricesOperation';
export * from './GetMultipleTokenPricesOperation';
export * from './GetWalletHistoryOperation';
export * from './GetWalletTokenBalancesPriceOperation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { GetNFTTradesOperation } from './GetNFTTradesOperation';
import { GetNFTContractSalePricesOperation } from './GetNFTContractSalePricesOperation';
import { GetNFTSalePricesOperation } from './GetNFTSalePricesOperation';
import { GetMultipleTokenPricesOperation } from './GetMultipleTokenPricesOperation';
import { GetWalletHistoryOperation } from './GetWalletHistoryOperation';
import { GetWalletTokenBalancesPriceOperation } from './GetWalletTokenBalancesPriceOperation';
Expand All @@ -23,6 +25,8 @@ import { GetBlockStatsOperation } from './GetBlockStatsOperation';

export const operations = [
GetNFTTradesOperation,
GetNFTContractSalePricesOperation,
GetNFTSalePricesOperation,
GetMultipleTokenPricesOperation,
GetWalletHistoryOperation,
GetWalletTokenBalancesPriceOperation,
Expand Down
10 changes: 10 additions & 0 deletions packages/common/evmUtils/src/generated/types/EvmNetWorthResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { EvmChainNetWorth, EvmChainNetWorthInput, EvmChainNetWorthJSON } from '.
// properties:
// - total_networth_usd ($ref: #/components/schemas/netWorthResult/properties/total_networth_usd)
// - chains ($ref: #/components/schemas/chainNetWorth)
// - unsupported_chain_ids ($ref: #/components/schemas/netWorthResult/properties/unsupported_chain_ids)

export interface EvmNetWorthResultJSON {
readonly total_networth_usd: string;
readonly chains: EvmChainNetWorthJSON[];
readonly unsupported_chain_ids?: string[];
}

export interface EvmNetWorthResultInput {
readonly totalNetworthUsd: string;
readonly chains: EvmChainNetWorthInput[] | EvmChainNetWorth[];
readonly unsupportedChainIds?: string[];
}

export class EvmNetWorthResult {
Expand All @@ -28,6 +31,7 @@ export class EvmNetWorthResult {
const input: EvmNetWorthResultInput = {
totalNetworthUsd: json.total_networth_usd,
chains: json.chains.map((item) => EvmChainNetWorth.fromJSON(item)),
unsupportedChainIds: json.unsupported_chain_ids,
};
return EvmNetWorthResult.create(input);
}
Expand All @@ -37,16 +41,22 @@ export class EvmNetWorthResult {
*/
public readonly totalNetworthUsd: string;
public readonly chains: EvmChainNetWorth[];
/**
* @description The chain ids that are not supported
*/
public readonly unsupportedChainIds?: string[];

private constructor(input: EvmNetWorthResultInput) {
this.totalNetworthUsd = input.totalNetworthUsd;
this.chains = input.chains.map((item) => EvmChainNetWorth.create(item));
this.unsupportedChainIds = input.unsupportedChainIds;
}

public toJSON(): EvmNetWorthResultJSON {
return {
total_networth_usd: this.totalNetworthUsd,
chains: this.chains.map((item) => item.toJSON()),
unsupported_chain_ids: this.unsupportedChainIds,
}
}
}
88 changes: 88 additions & 0 deletions packages/common/evmUtils/src/generated/types/EvmSoldPrice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { EvmSoldPriceLastSale, EvmSoldPriceLastSaleInput, EvmSoldPriceLastSaleJSON } from '../types/EvmSoldPriceLastSale';
import { EvmSoldPriceLowestSale, EvmSoldPriceLowestSaleInput, EvmSoldPriceLowestSaleJSON } from '../types/EvmSoldPriceLowestSale';
import { EvmSoldPriceHighestSale, EvmSoldPriceHighestSaleInput, EvmSoldPriceHighestSaleJSON } from '../types/EvmSoldPriceHighestSale';
import { EvmSoldPriceAverageSale, EvmSoldPriceAverageSaleInput, EvmSoldPriceAverageSaleJSON } from '../types/EvmSoldPriceAverageSale';

// $ref: #/components/schemas/soldPrice
// type: soldPrice
// properties:
// - last_sale ($ref: #/components/schemas/soldPrice/properties/last_sale)
// - lowest_sale ($ref: #/components/schemas/soldPrice/properties/lowest_sale)
// - highest_sale ($ref: #/components/schemas/soldPrice/properties/highest_sale)
// - average_sale ($ref: #/components/schemas/soldPrice/properties/average_sale)
// - total_trades ($ref: #/components/schemas/soldPrice/properties/total_trades)

export interface EvmSoldPriceJSON {
readonly last_sale: EvmSoldPriceLastSaleJSON;
readonly lowest_sale: EvmSoldPriceLowestSaleJSON;
readonly highest_sale: EvmSoldPriceHighestSaleJSON;
readonly average_sale: EvmSoldPriceAverageSaleJSON;
readonly total_trades?: number;
}

export interface EvmSoldPriceInput {
readonly lastSale: EvmSoldPriceLastSaleInput | EvmSoldPriceLastSale;
readonly lowestSale: EvmSoldPriceLowestSaleInput | EvmSoldPriceLowestSale;
readonly highestSale: EvmSoldPriceHighestSaleInput | EvmSoldPriceHighestSale;
readonly averageSale: EvmSoldPriceAverageSaleInput | EvmSoldPriceAverageSale;
readonly totalTrades?: number;
}

export class EvmSoldPrice {
public static create(input: EvmSoldPriceInput | EvmSoldPrice): EvmSoldPrice {
if (input instanceof EvmSoldPrice) {
return input;
}
return new EvmSoldPrice(input);
}

public static fromJSON(json: EvmSoldPriceJSON): EvmSoldPrice {
const input: EvmSoldPriceInput = {
lastSale: EvmSoldPriceLastSale.fromJSON(json.last_sale),
lowestSale: EvmSoldPriceLowestSale.fromJSON(json.lowest_sale),
highestSale: EvmSoldPriceHighestSale.fromJSON(json.highest_sale),
averageSale: EvmSoldPriceAverageSale.fromJSON(json.average_sale),
totalTrades: json.total_trades,
};
return EvmSoldPrice.create(input);
}

/**
* @description The sales price of the NFT collection
*/
public readonly lastSale: EvmSoldPriceLastSale;
/**
* @description The lowest sale of the NFT collection
*/
public readonly lowestSale: EvmSoldPriceLowestSale;
/**
* @description The highest sale of the NFT collection
*/
public readonly highestSale: EvmSoldPriceHighestSale;
/**
* @description The average sale of the NFT collection
*/
public readonly averageSale: EvmSoldPriceAverageSale;
/**
* @description The total trades in the timeframe
*/
public readonly totalTrades?: number;

private constructor(input: EvmSoldPriceInput) {
this.lastSale = EvmSoldPriceLastSale.create(input.lastSale);
this.lowestSale = EvmSoldPriceLowestSale.create(input.lowestSale);
this.highestSale = EvmSoldPriceHighestSale.create(input.highestSale);
this.averageSale = EvmSoldPriceAverageSale.create(input.averageSale);
this.totalTrades = input.totalTrades;
}

public toJSON(): EvmSoldPriceJSON {
return {
last_sale: this.lastSale.toJSON(),
lowest_sale: this.lowestSale.toJSON(),
highest_sale: this.highestSale.toJSON(),
average_sale: this.averageSale.toJSON(),
total_trades: this.totalTrades,
}
}
}
Loading

0 comments on commit c2f2e58

Please sign in to comment.