diff --git a/.changeset/cuddly-walls-sin.md b/.changeset/cuddly-walls-sin.md new file mode 100644 index 0000000000..9a7f493123 --- /dev/null +++ b/.changeset/cuddly-walls-sin.md @@ -0,0 +1,7 @@ +--- +'@moralisweb3/common-evm-utils': patch +'@moralisweb3/evm-api': patch +'moralis': patch +--- + +Added the `getMultipleTokenPrices` method to the EVM API. diff --git a/packages/common/evmUtils/generator.config.json b/packages/common/evmUtils/generator.config.json index 3f4e4aae52..e0351aab57 100644 --- a/packages/common/evmUtils/generator.config.json +++ b/packages/common/evmUtils/generator.config.json @@ -79,7 +79,8 @@ "getNFTTokenStats", "getNFTCollectionStats", "getBlockStats", - "getTokenStats" + "getTokenStats", + "getMultipleTokenPrices" ] } } diff --git a/packages/common/evmUtils/src/generated/client/abstractClient.ts b/packages/common/evmUtils/src/generated/client/abstractClient.ts index d0f6deb3d6..5c8f7a25eb 100644 --- a/packages/common/evmUtils/src/generated/client/abstractClient.ts +++ b/packages/common/evmUtils/src/generated/client/abstractClient.ts @@ -1,5 +1,8 @@ import { GetNFTTradesOperation, GetNFTTradesOperationRequest, GetNFTTradesOperationRequestJSON } from '../operations/GetNFTTradesOperation'; import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCollection'; +import { GetMultipleTokenPricesOperation, GetMultipleTokenPricesOperationRequest, GetMultipleTokenPricesOperationRequestJSON } from '../operations/GetMultipleTokenPricesOperation'; +import { EvmErc20Price, EvmErc20PriceJSON } from '../types/EvmErc20Price'; +import { EvmGetMultipleTokenPricesDto, EvmGetMultipleTokenPricesDtoInput, EvmGetMultipleTokenPricesDtoJSON } from '../types/EvmGetMultipleTokenPricesDto'; import { Web3ApiVersionOperation, Web3ApiVersionOperationRequest, Web3ApiVersionOperationRequestJSON } from '../operations/Web3ApiVersionOperation'; import { EvmWeb3version, EvmWeb3versionJSON } from '../types/EvmWeb3version'; import { EndpointWeightsOperation, EndpointWeightsOperationRequest, EndpointWeightsOperationRequestJSON } from '../operations/EndpointWeightsOperation'; @@ -120,10 +123,10 @@ export abstract class AbstractClient { * * Provide the param 'from_block' or 'from_date' * * If 'from_date' and 'from_block' are provided, 'from_block' will be used. (optional) * @param {String} [request.toBlock] The block number to get the trades from (optional) - * @param {String} [request.fromDate] The start date from which to get the transfers (any format that is accepted by momentjs) + * @param {String} [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 {String} [request.toDate] The end date from which to get the transfers (any format that is accepted by momentjs) + * @param {String} [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 {Object} [request.marketplace] Marketplace from which to get the trades (only OpenSea is supported at the moment) (optional) @@ -166,6 +169,23 @@ export abstract class AbstractClient { >(GetNFTTokenStatsOperation), }; public readonly token = { + /** + * @description Returns an array of token prices denominated in the blockchain's native token and USD for a given token contract address + * @param request Request with parameters. + * @param {Object} [request.chain] The chain to query (optional) + * @param {Object} [request.include] If the result should contain the 24hr percent change (optional) + * @param body Request body. + * @param {Object[]} body.tokens The tokens to be fetched + * @returns {Object[]} Response for the request. + */ + getMultipleTokenPrices: this.createEndpointWithBody< + GetMultipleTokenPricesOperationRequest, + GetMultipleTokenPricesOperationRequestJSON, + EvmErc20Price[], + EvmErc20PriceJSON[], + EvmGetMultipleTokenPricesDtoInput | EvmGetMultipleTokenPricesDto, + EvmGetMultipleTokenPricesDtoJSON + >(GetMultipleTokenPricesOperation), /** * @description Get the stats for a erc20 token * @param request Request with parameters. diff --git a/packages/common/evmUtils/src/generated/operations/GetMultipleTokenPricesOperation.ts b/packages/common/evmUtils/src/generated/operations/GetMultipleTokenPricesOperation.ts new file mode 100644 index 0000000000..32180fff20 --- /dev/null +++ b/packages/common/evmUtils/src/generated/operations/GetMultipleTokenPricesOperation.ts @@ -0,0 +1,57 @@ +import { EvmChain, EvmChainInput, EvmChainJSON } from '../../dataTypes'; +import { EvmGetMultipleTokenPricesIncludeEnum, EvmGetMultipleTokenPricesIncludeEnumValue, EvmGetMultipleTokenPricesIncludeEnumInput, EvmGetMultipleTokenPricesIncludeEnumJSON } from '../types/EvmGetMultipleTokenPricesIncludeEnum'; +import { EvmErc20Price, EvmErc20PriceJSON } from '../types/EvmErc20Price'; +import { EvmGetMultipleTokenPricesDto, EvmGetMultipleTokenPricesDtoInput, EvmGetMultipleTokenPricesDtoJSON } from '../types/EvmGetMultipleTokenPricesDto'; + +// request parameters: +// - chain ($ref: #/components/schemas/chainList) +// - include ($ref: #/paths/~1erc20~1prices/post/parameters/1/schema) + +export interface GetMultipleTokenPricesOperationRequest { + /** + * @description The chain to query + */ + readonly chain?: EvmChainInput | EvmChain; + /** + * @description If the result should contain the 24hr percent change + */ + readonly include?: EvmGetMultipleTokenPricesIncludeEnumInput | EvmGetMultipleTokenPricesIncludeEnumValue; +} + +export interface GetMultipleTokenPricesOperationRequestJSON { + readonly chain?: EvmChainJSON; + readonly include?: EvmGetMultipleTokenPricesIncludeEnumJSON; +} + +export type GetMultipleTokenPricesOperationResponse = EvmErc20Price[]; +export type GetMultipleTokenPricesOperationResponseJSON = EvmErc20PriceJSON[]; + +export type GetMultipleTokenPricesOperationBody = EvmGetMultipleTokenPricesDtoInput | EvmGetMultipleTokenPricesDto; + +export const GetMultipleTokenPricesOperation = { + operationId: "getMultipleTokenPrices", + groupName: "token", + httpMethod: "post", + routePattern: "/erc20/prices", + parameterNames: ["chain","include"], + hasResponse: true, + hasBody: true, + + parseResponse(json: EvmErc20PriceJSON[]): EvmErc20Price[] { + return json.map((item) => EvmErc20Price.fromJSON(item)); + }, + + serializeRequest(request: GetMultipleTokenPricesOperationRequest): GetMultipleTokenPricesOperationRequestJSON { + const chain = request.chain ? EvmChain.create(request.chain) : undefined; + const include = request.include ? EvmGetMultipleTokenPricesIncludeEnum.create(request.include) : undefined; + return { + chain: chain ? chain.toJSON() : undefined, + include: include ? include : undefined, + }; + }, + + serializeBody(body: EvmGetMultipleTokenPricesDtoInput | EvmGetMultipleTokenPricesDto): EvmGetMultipleTokenPricesDtoJSON { + const value = EvmGetMultipleTokenPricesDto.create(body); + return value.toJSON(); + }, +} diff --git a/packages/common/evmUtils/src/generated/operations/GetNFTTradesOperation.ts b/packages/common/evmUtils/src/generated/operations/GetNFTTradesOperation.ts index 5c716ab3d8..8529549b0b 100644 --- a/packages/common/evmUtils/src/generated/operations/GetNFTTradesOperation.ts +++ b/packages/common/evmUtils/src/generated/operations/GetNFTTradesOperation.ts @@ -29,13 +29,13 @@ export interface GetNFTTradesOperationRequest { */ readonly toBlock?: string; /** - * @description The start date from which to get the transfers (any format that is accepted by momentjs) + * @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?: string; /** - * @description The end date from which to get the transfers (any format that is accepted by momentjs) + * @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. */ diff --git a/packages/common/evmUtils/src/generated/operations/index.ts b/packages/common/evmUtils/src/generated/operations/index.ts index 4de8e8121b..7b9a62ed29 100644 --- a/packages/common/evmUtils/src/generated/operations/index.ts +++ b/packages/common/evmUtils/src/generated/operations/index.ts @@ -1,4 +1,5 @@ export * from './GetNFTTradesOperation'; +export * from './GetMultipleTokenPricesOperation'; export * from './Web3ApiVersionOperation'; export * from './EndpointWeightsOperation'; export * from './GetTopERC20TokensByMarketCapOperation'; diff --git a/packages/common/evmUtils/src/generated/operations/operations.ts b/packages/common/evmUtils/src/generated/operations/operations.ts index ffc0055481..76527996a1 100644 --- a/packages/common/evmUtils/src/generated/operations/operations.ts +++ b/packages/common/evmUtils/src/generated/operations/operations.ts @@ -1,4 +1,5 @@ import { GetNFTTradesOperation } from './GetNFTTradesOperation'; +import { GetMultipleTokenPricesOperation } from './GetMultipleTokenPricesOperation'; import { Web3ApiVersionOperation } from './Web3ApiVersionOperation'; import { EndpointWeightsOperation } from './EndpointWeightsOperation'; import { GetTopERC20TokensByMarketCapOperation } from './GetTopERC20TokensByMarketCapOperation'; @@ -15,6 +16,7 @@ import { GetBlockStatsOperation } from './GetBlockStatsOperation'; export const operations = [ GetNFTTradesOperation, + GetMultipleTokenPricesOperation, Web3ApiVersionOperation, EndpointWeightsOperation, GetTopERC20TokensByMarketCapOperation, diff --git a/packages/common/evmUtils/src/generated/types/EvmChainList.ts b/packages/common/evmUtils/src/generated/types/EvmChainList.ts index 14e7ff123a..d8ff44eecc 100644 --- a/packages/common/evmUtils/src/generated/types/EvmChainList.ts +++ b/packages/common/evmUtils/src/generated/types/EvmChainList.ts @@ -1,9 +1,9 @@ // $ref: #/components/schemas/chainList // typeName: chainList -export type EvmChainListJSON = "eth" | "0x1" | "goerli" | "0x5" | "sepolia" | "0xaa36a7" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | "avalanche" | "0xa86a" | "fantom" | "0xfa" | "palm" | "0x2a15c308d" | "cronos" | "0x19" | "arbitrum" | "0xa4b1"; -export type EvmChainListInput = "eth" | "0x1" | "goerli" | "0x5" | "sepolia" | "0xaa36a7" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | "avalanche" | "0xa86a" | "fantom" | "0xfa" | "palm" | "0x2a15c308d" | "cronos" | "0x19" | "arbitrum" | "0xa4b1"; -export type EvmChainListValue = "eth" | "0x1" | "goerli" | "0x5" | "sepolia" | "0xaa36a7" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | "avalanche" | "0xa86a" | "fantom" | "0xfa" | "palm" | "0x2a15c308d" | "cronos" | "0x19" | "arbitrum" | "0xa4b1"; +export type EvmChainListJSON = "eth" | "0x1" | "goerli" | "0x5" | "sepolia" | "0xaa36a7" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | "avalanche" | "0xa86a" | "fantom" | "0xfa" | "palm" | "0x2a15c308d" | "cronos" | "0x19" | "arbitrum" | "0xa4b1" | "chiliz" | "0x15b38" | "chiliz testnet" | "0x15b32" | "gnosis" | "0x64" | "gnosis testnet" | "0x27d8" | "base" | "0x2105" | "base testnet" | "0x14a33" | "optimism" | "0xa"; +export type EvmChainListInput = "eth" | "0x1" | "goerli" | "0x5" | "sepolia" | "0xaa36a7" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | "avalanche" | "0xa86a" | "fantom" | "0xfa" | "palm" | "0x2a15c308d" | "cronos" | "0x19" | "arbitrum" | "0xa4b1" | "chiliz" | "0x15b38" | "chiliz testnet" | "0x15b32" | "gnosis" | "0x64" | "gnosis testnet" | "0x27d8" | "base" | "0x2105" | "base testnet" | "0x14a33" | "optimism" | "0xa"; +export type EvmChainListValue = "eth" | "0x1" | "goerli" | "0x5" | "sepolia" | "0xaa36a7" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | "avalanche" | "0xa86a" | "fantom" | "0xfa" | "palm" | "0x2a15c308d" | "cronos" | "0x19" | "arbitrum" | "0xa4b1" | "chiliz" | "0x15b38" | "chiliz testnet" | "0x15b32" | "gnosis" | "0x64" | "gnosis testnet" | "0x27d8" | "base" | "0x2105" | "base testnet" | "0x14a33" | "optimism" | "0xa"; export abstract class EvmChainList { public static create(input: EvmChainListInput | EvmChainListValue): EvmChainListValue { diff --git a/packages/common/evmUtils/src/generated/types/EvmErc20Price.ts b/packages/common/evmUtils/src/generated/types/EvmErc20Price.ts new file mode 100644 index 0000000000..78a93715c1 --- /dev/null +++ b/packages/common/evmUtils/src/generated/types/EvmErc20Price.ts @@ -0,0 +1,162 @@ +import { EvmNativeErc20Price, EvmNativeErc20PriceInput, EvmNativeErc20PriceJSON } from '../types/EvmNativeErc20Price'; + +// $ref: #/components/schemas/erc20Price +// type: erc20Price +// properties: +// - tokenName ($ref: #/components/schemas/erc20Price/properties/tokenName) +// - tokenSymbol ($ref: #/components/schemas/erc20Price/properties/tokenSymbol) +// - tokenLogo ($ref: #/components/schemas/erc20Price/properties/tokenLogo) +// - tokenDecimals ($ref: #/components/schemas/erc20Price/properties/tokenDecimals) +// - nativePrice ($ref: #/components/schemas/nativeErc20Price) +// - usdPrice ($ref: #/components/schemas/erc20Price/properties/usdPrice) +// - usdPriceFormatted ($ref: #/components/schemas/erc20Price/properties/usdPriceFormatted) +// - 24hrPercentChange ($ref: #/components/schemas/erc20Price/properties/24hrPercentChange) +// - exchangeAddress ($ref: #/components/schemas/erc20Price/properties/exchangeAddress) +// - exchangeName ($ref: #/components/schemas/erc20Price/properties/exchangeName) +// - tokenAddress ($ref: #/components/schemas/erc20Price/properties/tokenAddress) +// - toBlock ($ref: #/components/schemas/erc20Price/properties/toBlock) +// - verifiedContract ($ref: #/components/schemas/erc20Price/properties/verifiedContract) + +export interface EvmErc20PriceJSON { + readonly tokenName?: string; + readonly tokenSymbol?: string; + readonly tokenLogo?: string; + readonly tokenDecimals?: string; + readonly nativePrice?: EvmNativeErc20PriceJSON; + readonly usdPrice: number; + readonly usdPriceFormatted?: string; + readonly '24hrPercentChange'?: string; + readonly exchangeAddress?: string; + readonly exchangeName?: string; + readonly tokenAddress?: string; + readonly toBlock?: string; + readonly verifiedContract?: boolean; +} + +export interface EvmErc20PriceInput { + readonly tokenName?: string; + readonly tokenSymbol?: string; + readonly tokenLogo?: string; + readonly tokenDecimals?: string; + readonly nativePrice?: EvmNativeErc20PriceInput | EvmNativeErc20Price; + readonly usdPrice: number; + readonly usdPriceFormatted?: string; + readonly '24hrPercentChange'?: string; + readonly exchangeAddress?: string; + readonly exchangeName?: string; + readonly tokenAddress?: string; + readonly toBlock?: string; + readonly verifiedContract?: boolean; +} + +export class EvmErc20Price { + public static create(input: EvmErc20PriceInput | EvmErc20Price): EvmErc20Price { + if (input instanceof EvmErc20Price) { + return input; + } + return new EvmErc20Price(input); + } + + public static fromJSON(json: EvmErc20PriceJSON): EvmErc20Price { + const input: EvmErc20PriceInput = { + tokenName: json.tokenName, + tokenSymbol: json.tokenSymbol, + tokenLogo: json.tokenLogo, + tokenDecimals: json.tokenDecimals, + nativePrice: json.nativePrice ? EvmNativeErc20Price.fromJSON(json.nativePrice) : undefined, + usdPrice: json.usdPrice, + usdPriceFormatted: json.usdPriceFormatted, + '24hrPercentChange': json['24hrPercentChange'], + exchangeAddress: json.exchangeAddress, + exchangeName: json.exchangeName, + tokenAddress: json.tokenAddress, + toBlock: json.toBlock, + verifiedContract: json.verifiedContract, + }; + return EvmErc20Price.create(input); + } + + /** + * @description The name of the token + */ + public readonly tokenName?: string; + /** + * @description The symbol of the token + */ + public readonly tokenSymbol?: string; + /** + * @description The logo of the token + */ + public readonly tokenLogo?: string; + /** + * @description The number of decimals of the token + */ + public readonly tokenDecimals?: string; + public readonly nativePrice?: EvmNativeErc20Price; + /** + * @description The price in USD for the token + */ + public readonly usdPrice: number; + /** + * @description The price in USD for the token in string format + */ + public readonly usdPriceFormatted?: string; + /** + * @description The 24hr percent change of the token + */ + public readonly '24hrPercentChange'?: string; + /** + * @description The address of the exchange used to calculate the price + */ + public readonly exchangeAddress?: string; + /** + * @description The name of the exchange used to calculate the price + */ + public readonly exchangeName?: string; + /** + * @description The address of the token + */ + public readonly tokenAddress?: string; + /** + * @description toBlock + */ + public readonly toBlock?: string; + /** + * @description Indicates if the contract is verified + */ + public readonly verifiedContract?: boolean; + + private constructor(input: EvmErc20PriceInput) { + this.tokenName = input.tokenName; + this.tokenSymbol = input.tokenSymbol; + this.tokenLogo = input.tokenLogo; + this.tokenDecimals = input.tokenDecimals; + this.nativePrice = input.nativePrice ? EvmNativeErc20Price.create(input.nativePrice) : undefined; + this.usdPrice = input.usdPrice; + this.usdPriceFormatted = input.usdPriceFormatted; + this['24hrPercentChange'] = input['24hrPercentChange']; + this.exchangeAddress = input.exchangeAddress; + this.exchangeName = input.exchangeName; + this.tokenAddress = input.tokenAddress; + this.toBlock = input.toBlock; + this.verifiedContract = input.verifiedContract; + } + + public toJSON(): EvmErc20PriceJSON { + return { + tokenName: this.tokenName, + tokenSymbol: this.tokenSymbol, + tokenLogo: this.tokenLogo, + tokenDecimals: this.tokenDecimals, + nativePrice: this.nativePrice ? this.nativePrice.toJSON() : undefined, + usdPrice: this.usdPrice, + usdPriceFormatted: this.usdPriceFormatted, + '24hrPercentChange': this['24hrPercentChange'], + exchangeAddress: this.exchangeAddress, + exchangeName: this.exchangeName, + tokenAddress: this.tokenAddress, + toBlock: this.toBlock, + verifiedContract: this.verifiedContract, + } + } +} diff --git a/packages/common/evmUtils/src/generated/types/EvmGetMultipleTokenPricesDto.ts b/packages/common/evmUtils/src/generated/types/EvmGetMultipleTokenPricesDto.ts new file mode 100644 index 0000000000..ba0f6e0227 --- /dev/null +++ b/packages/common/evmUtils/src/generated/types/EvmGetMultipleTokenPricesDto.ts @@ -0,0 +1,45 @@ +import { EvmTokenPriceItem, EvmTokenPriceItemInput, EvmTokenPriceItemJSON } from '../types/EvmTokenPriceItem'; + +// $ref: #/components/schemas/GetMultipleTokenPricesDto +// type: GetMultipleTokenPricesDto +// properties: +// - tokens ($ref: #/components/schemas/tokenPriceItem) + +export interface EvmGetMultipleTokenPricesDtoJSON { + readonly tokens: EvmTokenPriceItemJSON[]; +} + +export interface EvmGetMultipleTokenPricesDtoInput { + readonly tokens: EvmTokenPriceItemInput[] | EvmTokenPriceItem[]; +} + +export class EvmGetMultipleTokenPricesDto { + public static create(input: EvmGetMultipleTokenPricesDtoInput | EvmGetMultipleTokenPricesDto): EvmGetMultipleTokenPricesDto { + if (input instanceof EvmGetMultipleTokenPricesDto) { + return input; + } + return new EvmGetMultipleTokenPricesDto(input); + } + + public static fromJSON(json: EvmGetMultipleTokenPricesDtoJSON): EvmGetMultipleTokenPricesDto { + const input: EvmGetMultipleTokenPricesDtoInput = { + tokens: json.tokens.map((item) => EvmTokenPriceItem.fromJSON(item)), + }; + return EvmGetMultipleTokenPricesDto.create(input); + } + + /** + * @description The tokens to be fetched + */ + public readonly tokens: EvmTokenPriceItem[]; + + private constructor(input: EvmGetMultipleTokenPricesDtoInput) { + this.tokens = input.tokens.map((item) => EvmTokenPriceItem.create(item)); + } + + public toJSON(): EvmGetMultipleTokenPricesDtoJSON { + return { + tokens: this.tokens.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/evmUtils/src/generated/types/EvmGetMultipleTokenPricesIncludeEnum.ts b/packages/common/evmUtils/src/generated/types/EvmGetMultipleTokenPricesIncludeEnum.ts new file mode 100644 index 0000000000..0e31018d85 --- /dev/null +++ b/packages/common/evmUtils/src/generated/types/EvmGetMultipleTokenPricesIncludeEnum.ts @@ -0,0 +1,16 @@ +// $ref: #/paths/~1erc20~1prices/post/parameters/1/schema +// typeName: getMultipleTokenPrices_include_Enum + +export type EvmGetMultipleTokenPricesIncludeEnumJSON = "percent_change"; +export type EvmGetMultipleTokenPricesIncludeEnumInput = "percent_change"; +export type EvmGetMultipleTokenPricesIncludeEnumValue = "percent_change"; + +export abstract class EvmGetMultipleTokenPricesIncludeEnum { + public static create(input: EvmGetMultipleTokenPricesIncludeEnumInput | EvmGetMultipleTokenPricesIncludeEnumValue): EvmGetMultipleTokenPricesIncludeEnumValue { + return input; + } + + public static fromJSON(json: EvmGetMultipleTokenPricesIncludeEnumJSON): EvmGetMultipleTokenPricesIncludeEnumValue { + return json; + } +} diff --git a/packages/common/evmUtils/src/generated/types/EvmNativeErc20Price.ts b/packages/common/evmUtils/src/generated/types/EvmNativeErc20Price.ts new file mode 100644 index 0000000000..8f7263beb9 --- /dev/null +++ b/packages/common/evmUtils/src/generated/types/EvmNativeErc20Price.ts @@ -0,0 +1,83 @@ +// $ref: #/components/schemas/nativeErc20Price +// type: nativeErc20Price +// properties: +// - value ($ref: #/components/schemas/nativeErc20Price/properties/value) +// - decimals ($ref: #/components/schemas/nativeErc20Price/properties/decimals) +// - name ($ref: #/components/schemas/nativeErc20Price/properties/name) +// - symbol ($ref: #/components/schemas/nativeErc20Price/properties/symbol) +// - address ($ref: #/components/schemas/nativeErc20Price/properties/address) + +export interface EvmNativeErc20PriceJSON { + readonly value: string; + readonly decimals: number; + readonly name: string; + readonly symbol: string; + readonly address: string; +} + +export interface EvmNativeErc20PriceInput { + readonly value: string; + readonly decimals: number; + readonly name: string; + readonly symbol: string; + readonly address: string; +} + +export class EvmNativeErc20Price { + public static create(input: EvmNativeErc20PriceInput | EvmNativeErc20Price): EvmNativeErc20Price { + if (input instanceof EvmNativeErc20Price) { + return input; + } + return new EvmNativeErc20Price(input); + } + + public static fromJSON(json: EvmNativeErc20PriceJSON): EvmNativeErc20Price { + const input: EvmNativeErc20PriceInput = { + value: json.value, + decimals: json.decimals, + name: json.name, + symbol: json.symbol, + address: json.address, + }; + return EvmNativeErc20Price.create(input); + } + + /** + * @description The native price of the token + */ + public readonly value: string; + /** + * @description The number of decimals on the token + */ + public readonly decimals: number; + /** + * @description The name of the token + */ + public readonly name: string; + /** + * @description The symbol of the token + */ + public readonly symbol: string; + /** + * @description The address of the native token + */ + public readonly address: string; + + private constructor(input: EvmNativeErc20PriceInput) { + this.value = input.value; + this.decimals = input.decimals; + this.name = input.name; + this.symbol = input.symbol; + this.address = input.address; + } + + public toJSON(): EvmNativeErc20PriceJSON { + return { + value: this.value, + decimals: this.decimals, + name: this.name, + symbol: this.symbol, + address: this.address, + } + } +} diff --git a/packages/common/evmUtils/src/generated/types/EvmTokenPriceItem.ts b/packages/common/evmUtils/src/generated/types/EvmTokenPriceItem.ts new file mode 100644 index 0000000000..21569ee67e --- /dev/null +++ b/packages/common/evmUtils/src/generated/types/EvmTokenPriceItem.ts @@ -0,0 +1,65 @@ +import { EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/tokenPriceItem +// type: tokenPriceItem +// properties: +// - token_address ($ref: #/components/schemas/tokenPriceItem/properties/token_address) +// - exchange ($ref: #/components/schemas/tokenPriceItem/properties/exchange) +// - to_block ($ref: #/components/schemas/tokenPriceItem/properties/to_block) + +export interface EvmTokenPriceItemJSON { + readonly token_address: EvmAddressJSON; + readonly exchange?: string; + readonly to_block?: string; +} + +export interface EvmTokenPriceItemInput { + readonly tokenAddress: EvmAddressInput | EvmAddress; + readonly exchange?: string; + readonly toBlock?: string; +} + +export class EvmTokenPriceItem { + public static create(input: EvmTokenPriceItemInput | EvmTokenPriceItem): EvmTokenPriceItem { + if (input instanceof EvmTokenPriceItem) { + return input; + } + return new EvmTokenPriceItem(input); + } + + public static fromJSON(json: EvmTokenPriceItemJSON): EvmTokenPriceItem { + const input: EvmTokenPriceItemInput = { + tokenAddress: EvmAddress.fromJSON(json.token_address), + exchange: json.exchange, + toBlock: json.to_block, + }; + return EvmTokenPriceItem.create(input); + } + + /** + * @description The contract address + */ + public readonly tokenAddress: EvmAddress; + /** + * @description The exchange + */ + public readonly exchange?: string; + /** + * @description The block number + */ + public readonly toBlock?: string; + + private constructor(input: EvmTokenPriceItemInput) { + this.tokenAddress = EvmAddress.create(input.tokenAddress); + this.exchange = input.exchange; + this.toBlock = input.toBlock; + } + + public toJSON(): EvmTokenPriceItemJSON { + return { + token_address: this.tokenAddress.toJSON(), + exchange: this.exchange, + to_block: this.toBlock, + } + } +} diff --git a/packages/common/evmUtils/src/generated/types/index.ts b/packages/common/evmUtils/src/generated/types/index.ts index 891d20bf27..c7983879f9 100644 --- a/packages/common/evmUtils/src/generated/types/index.ts +++ b/packages/common/evmUtils/src/generated/types/index.ts @@ -1,8 +1,11 @@ export * from './EvmChainList'; export * from './EvmGetNFTTradesMarketplaceEnum'; +export * from './EvmGetMultipleTokenPricesIncludeEnum'; export * from './EvmContractsReviewItemReportTypeEnum'; export * from './EvmContractsReviewItemContractTypeEnum'; export * from './EvmTradeCollection'; +export * from './EvmErc20Price'; +export * from './EvmGetMultipleTokenPricesDto'; export * from './EvmWeb3version'; export * from './EvmEndpointWeights'; export * from './EvmMarketDataERC20TokenItem'; @@ -18,6 +21,8 @@ export * from './EvmNftTokenStat'; export * from './EvmErc20TokenStat'; export * from './EvmBlockTokenStat'; export * from './EvmTrade'; +export * from './EvmNativeErc20Price'; +export * from './EvmTokenPriceItem'; export * from './EvmContractsReviewItem'; export * from './EvmWalletActiveChain'; export * from './EvmWalletStatTransactions'; diff --git a/packages/evmApi/src/generated/ClientEvmApi.ts b/packages/evmApi/src/generated/ClientEvmApi.ts index edda4d7b10..30d6c25ac9 100644 --- a/packages/evmApi/src/generated/ClientEvmApi.ts +++ b/packages/evmApi/src/generated/ClientEvmApi.ts @@ -1,6 +1,6 @@ // CAUTION: This file is automatically generated. Do not edit it manually! -import { getBlockOperation, GetBlockRequest, GetBlockResponseAdapter, getDateToBlockOperation, GetDateToBlockRequest, GetDateToBlockResponseAdapter, GetBlockStatsOperationResponseJSON, GetBlockStatsOperation, GetBlockStatsOperationRequest, GetBlockStatsOperationResponse, getContractEventsOperation, GetContractEventsRequest, GetContractEventsResponseAdapter, getContractLogsOperation, GetContractLogsRequest, GetContractLogsResponseAdapter, getContractNFTsOperation, GetContractNFTsRequest, GetContractNFTsResponseAdapter, getMultipleNFTsOperation, GetMultipleNFTsRequest, GetMultipleNFTsResponseAdapter, getNFTContractMetadataOperation, GetNFTContractMetadataRequest, GetNFTContractMetadataResponseAdapter, getNFTContractTransfersOperation, GetNFTContractTransfersRequest, GetNFTContractTransfersResponseAdapter, getNFTLowestPriceOperation, GetNFTLowestPriceRequest, GetNFTLowestPriceResponseAdapter, getNFTMetadataOperation, GetNFTMetadataRequest, GetNFTMetadataResponseAdapter, getNFTOwnersOperation, GetNFTOwnersRequest, GetNFTOwnersResponseAdapter, getNFTTokenIdOwnersOperation, GetNFTTokenIdOwnersRequest, GetNFTTokenIdOwnersResponseAdapter, getNFTTransfersByBlockOperation, GetNFTTransfersByBlockRequest, GetNFTTransfersByBlockResponseAdapter, getNFTTransfersFromToBlockOperation, GetNFTTransfersFromToBlockRequest, GetNFTTransfersFromToBlockResponseAdapter, getNFTTransfersOperation, GetNFTTransfersRequest, GetNFTTransfersResponseAdapter, getWalletNFTCollectionsOperation, GetWalletNFTCollectionsRequest, GetWalletNFTCollectionsResponseAdapter, getWalletNFTsOperation, GetWalletNFTsRequest, GetWalletNFTsResponseAdapter, getWalletNFTTransfersOperation, GetWalletNFTTransfersRequest, GetWalletNFTTransfersResponseAdapter, reSyncMetadataOperation, ReSyncMetadataRequest, ReSyncMetadataResponseAdapter, syncNFTContractOperation, SyncNFTContractRequest, SyncNFTContractResponseAdapter, GetNFTTradesOperationResponseJSON, GetNFTTradesOperation, GetNFTTradesOperationRequest, GetNFTTradesOperationResponse, GetNFTCollectionStatsOperationResponseJSON, GetNFTCollectionStatsOperation, GetNFTCollectionStatsOperationRequest, GetNFTCollectionStatsOperationResponse, GetNFTTokenStatsOperationResponseJSON, GetNFTTokenStatsOperation, GetNFTTokenStatsOperationRequest, GetNFTTokenStatsOperationResponse, getInternalTransactionsOperation, GetInternalTransactionsRequest, GetInternalTransactionsResponseAdapter, getTransactionOperation, GetTransactionRequest, GetTransactionResponseAdapter, getTransactionVerboseOperation, GetTransactionVerboseRequest, GetTransactionVerboseResponseAdapter, getWalletTransactionsOperation, GetWalletTransactionsRequest, GetWalletTransactionsResponseAdapter, getWalletTransactionsVerboseOperation, GetWalletTransactionsVerboseRequest, GetWalletTransactionsVerboseResponseAdapter, getNativeBalanceOperation, GetNativeBalanceRequest, GetNativeBalanceResponseAdapter, getNativeBalancesForAddressesOperation, GetNativeBalancesForAddressesRequest, GetNativeBalancesForAddressesResponseAdapter, getPairAddressOperation, GetPairAddressRequest, GetPairAddressResponseAdapter, getPairReservesOperation, GetPairReservesRequest, GetPairReservesResponseAdapter, getTokenAllowanceOperation, GetTokenAllowanceRequest, GetTokenAllowanceResponseAdapter, getTokenMetadataBySymbolOperation, GetTokenMetadataBySymbolRequest, GetTokenMetadataBySymbolResponseAdapter, getTokenMetadataOperation, GetTokenMetadataRequest, GetTokenMetadataResponseAdapter, getTokenPriceOperation, GetTokenPriceRequest, GetTokenPriceResponseAdapter, getTokenTransfersOperation, GetTokenTransfersRequest, GetTokenTransfersResponseAdapter, getWalletTokenBalancesOperation, GetWalletTokenBalancesRequest, GetWalletTokenBalancesResponseAdapter, getWalletTokenTransfersOperation, GetWalletTokenTransfersRequest, GetWalletTokenTransfersResponseAdapter, GetTokenStatsOperationResponseJSON, GetTokenStatsOperation, GetTokenStatsOperationRequest, GetTokenStatsOperationResponse, resolveAddressOperation, ResolveAddressRequest, ResolveAddressResponseAdapter, resolveDomainOperation, ResolveDomainRequest, ResolveDomainResponseAdapter, resolveENSDomainOperation, ResolveENSDomainRequest, ResolveENSDomainResponseAdapter, runContractFunctionOperation, RunContractFunctionRequest, RunContractFunctionResponseAdapter, Web3ApiVersionOperationResponseJSON, Web3ApiVersionOperation, Web3ApiVersionOperationResponse, EndpointWeightsOperationResponseJSON, EndpointWeightsOperation, EndpointWeightsOperationResponse, ReviewContractsOperationResponseJSON, ReviewContractsOperation, ReviewContractsOperationRequest, ReviewContractsOperationBody, ReviewContractsOperationResponse, uploadFolderOperation, UploadFolderRequest, UploadFolderResponseAdapter, GetTopERC20TokensByMarketCapOperationResponseJSON, GetTopERC20TokensByMarketCapOperation, GetTopERC20TokensByMarketCapOperationResponse, GetTopERC20TokensByPriceMoversOperationResponseJSON, GetTopERC20TokensByPriceMoversOperation, GetTopERC20TokensByPriceMoversOperationResponse, GetTopNFTCollectionsByMarketCapOperationResponseJSON, GetTopNFTCollectionsByMarketCapOperation, GetTopNFTCollectionsByMarketCapOperationResponse, GetHottestNFTCollectionsByTradingVolumeOperationResponseJSON, GetHottestNFTCollectionsByTradingVolumeOperation, GetHottestNFTCollectionsByTradingVolumeOperationResponse, GetWalletActiveChainsOperationResponseJSON, GetWalletActiveChainsOperation, GetWalletActiveChainsOperationRequest, GetWalletActiveChainsOperationResponse, GetWalletStatsOperationResponseJSON, GetWalletStatsOperation, GetWalletStatsOperationRequest, GetWalletStatsOperationResponse } from '@moralisweb3/common-evm-utils'; +import { getBlockOperation, GetBlockRequest, GetBlockResponseAdapter, getDateToBlockOperation, GetDateToBlockRequest, GetDateToBlockResponseAdapter, GetBlockStatsOperationResponseJSON, GetBlockStatsOperation, GetBlockStatsOperationRequest, GetBlockStatsOperationResponse, getContractEventsOperation, GetContractEventsRequest, GetContractEventsResponseAdapter, getContractLogsOperation, GetContractLogsRequest, GetContractLogsResponseAdapter, getContractNFTsOperation, GetContractNFTsRequest, GetContractNFTsResponseAdapter, getMultipleNFTsOperation, GetMultipleNFTsRequest, GetMultipleNFTsResponseAdapter, getNFTContractMetadataOperation, GetNFTContractMetadataRequest, GetNFTContractMetadataResponseAdapter, getNFTContractTransfersOperation, GetNFTContractTransfersRequest, GetNFTContractTransfersResponseAdapter, getNFTLowestPriceOperation, GetNFTLowestPriceRequest, GetNFTLowestPriceResponseAdapter, getNFTMetadataOperation, GetNFTMetadataRequest, GetNFTMetadataResponseAdapter, getNFTOwnersOperation, GetNFTOwnersRequest, GetNFTOwnersResponseAdapter, getNFTTokenIdOwnersOperation, GetNFTTokenIdOwnersRequest, GetNFTTokenIdOwnersResponseAdapter, getNFTTransfersByBlockOperation, GetNFTTransfersByBlockRequest, GetNFTTransfersByBlockResponseAdapter, getNFTTransfersFromToBlockOperation, GetNFTTransfersFromToBlockRequest, GetNFTTransfersFromToBlockResponseAdapter, getNFTTransfersOperation, GetNFTTransfersRequest, GetNFTTransfersResponseAdapter, getWalletNFTCollectionsOperation, GetWalletNFTCollectionsRequest, GetWalletNFTCollectionsResponseAdapter, getWalletNFTsOperation, GetWalletNFTsRequest, GetWalletNFTsResponseAdapter, getWalletNFTTransfersOperation, GetWalletNFTTransfersRequest, GetWalletNFTTransfersResponseAdapter, reSyncMetadataOperation, ReSyncMetadataRequest, ReSyncMetadataResponseAdapter, syncNFTContractOperation, SyncNFTContractRequest, SyncNFTContractResponseAdapter, GetNFTTradesOperationResponseJSON, GetNFTTradesOperation, GetNFTTradesOperationRequest, GetNFTTradesOperationResponse, GetNFTCollectionStatsOperationResponseJSON, GetNFTCollectionStatsOperation, GetNFTCollectionStatsOperationRequest, GetNFTCollectionStatsOperationResponse, GetNFTTokenStatsOperationResponseJSON, GetNFTTokenStatsOperation, GetNFTTokenStatsOperationRequest, GetNFTTokenStatsOperationResponse, getInternalTransactionsOperation, GetInternalTransactionsRequest, GetInternalTransactionsResponseAdapter, getTransactionOperation, GetTransactionRequest, GetTransactionResponseAdapter, getTransactionVerboseOperation, GetTransactionVerboseRequest, GetTransactionVerboseResponseAdapter, getWalletTransactionsOperation, GetWalletTransactionsRequest, GetWalletTransactionsResponseAdapter, getWalletTransactionsVerboseOperation, GetWalletTransactionsVerboseRequest, GetWalletTransactionsVerboseResponseAdapter, getNativeBalanceOperation, GetNativeBalanceRequest, GetNativeBalanceResponseAdapter, getNativeBalancesForAddressesOperation, GetNativeBalancesForAddressesRequest, GetNativeBalancesForAddressesResponseAdapter, getPairAddressOperation, GetPairAddressRequest, GetPairAddressResponseAdapter, getPairReservesOperation, GetPairReservesRequest, GetPairReservesResponseAdapter, getTokenAllowanceOperation, GetTokenAllowanceRequest, GetTokenAllowanceResponseAdapter, getTokenMetadataBySymbolOperation, GetTokenMetadataBySymbolRequest, GetTokenMetadataBySymbolResponseAdapter, getTokenMetadataOperation, GetTokenMetadataRequest, GetTokenMetadataResponseAdapter, getTokenPriceOperation, GetTokenPriceRequest, GetTokenPriceResponseAdapter, getTokenTransfersOperation, GetTokenTransfersRequest, GetTokenTransfersResponseAdapter, getWalletTokenBalancesOperation, GetWalletTokenBalancesRequest, GetWalletTokenBalancesResponseAdapter, getWalletTokenTransfersOperation, GetWalletTokenTransfersRequest, GetWalletTokenTransfersResponseAdapter, GetMultipleTokenPricesOperationResponseJSON, GetMultipleTokenPricesOperation, GetMultipleTokenPricesOperationRequest, GetMultipleTokenPricesOperationBody, GetMultipleTokenPricesOperationResponse, GetTokenStatsOperationResponseJSON, GetTokenStatsOperation, GetTokenStatsOperationRequest, GetTokenStatsOperationResponse, resolveAddressOperation, ResolveAddressRequest, ResolveAddressResponseAdapter, resolveDomainOperation, ResolveDomainRequest, ResolveDomainResponseAdapter, resolveENSDomainOperation, ResolveENSDomainRequest, ResolveENSDomainResponseAdapter, runContractFunctionOperation, RunContractFunctionRequest, RunContractFunctionResponseAdapter, Web3ApiVersionOperationResponseJSON, Web3ApiVersionOperation, Web3ApiVersionOperationResponse, EndpointWeightsOperationResponseJSON, EndpointWeightsOperation, EndpointWeightsOperationResponse, ReviewContractsOperationResponseJSON, ReviewContractsOperation, ReviewContractsOperationRequest, ReviewContractsOperationBody, ReviewContractsOperationResponse, uploadFolderOperation, UploadFolderRequest, UploadFolderResponseAdapter, GetTopERC20TokensByMarketCapOperationResponseJSON, GetTopERC20TokensByMarketCapOperation, GetTopERC20TokensByMarketCapOperationResponse, GetTopERC20TokensByPriceMoversOperationResponseJSON, GetTopERC20TokensByPriceMoversOperation, GetTopERC20TokensByPriceMoversOperationResponse, GetTopNFTCollectionsByMarketCapOperationResponseJSON, GetTopNFTCollectionsByMarketCapOperation, GetTopNFTCollectionsByMarketCapOperationResponse, GetHottestNFTCollectionsByTradingVolumeOperationResponseJSON, GetHottestNFTCollectionsByTradingVolumeOperation, GetHottestNFTCollectionsByTradingVolumeOperationResponse, GetWalletActiveChainsOperationResponseJSON, GetWalletActiveChainsOperation, GetWalletActiveChainsOperationRequest, GetWalletActiveChainsOperationResponse, GetWalletStatsOperationResponseJSON, GetWalletStatsOperation, GetWalletStatsOperationRequest, GetWalletStatsOperationResponse } from '@moralisweb3/common-evm-utils'; import { NullableOperationResolver, OperationResolver, OperationV3Resolver, PaginatedOperationResolver, PaginatedResponseV3Adapter, PaginatedOperationV3Resolver } from '@moralisweb3/api-utils'; import { ApiModule, ResponseAdapter } from '@moralisweb3/common-core'; export abstract class ClientEvmApi extends ApiModule { @@ -150,6 +150,9 @@ export abstract class ClientEvmApi extends ApiModule { getWalletTokenTransfers: (request: GetWalletTokenTransfersRequest): Promise => { return new PaginatedOperationResolver(getWalletTokenTransfersOperation, this.baseUrl, this.core).fetch(request); }, + getMultipleTokenPrices: (request: GetMultipleTokenPricesOperationRequest, body: GetMultipleTokenPricesOperationBody): Promise> => { + return new OperationV3Resolver(GetMultipleTokenPricesOperation, this.baseUrl, this.core).fetch(request, body); + }, getTokenStats: (request: GetTokenStatsOperationRequest): Promise> => { return new OperationV3Resolver(GetTokenStatsOperation, this.baseUrl, this.core).fetch(request, null); },