-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: getMultipleTokenPrices (#1175)
* feat: add `getMultipleTokenPrices`
- Loading branch information
Showing
15 changed files
with
476 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 the `getMultipleTokenPrices` method to the EVM API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/common/evmUtils/src/generated/operations/GetMultipleTokenPricesOperation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
packages/common/evmUtils/src/generated/types/EvmErc20Price.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/common/evmUtils/src/generated/types/EvmGetMultipleTokenPricesDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()), | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/common/evmUtils/src/generated/types/EvmGetMultipleTokenPricesIncludeEnum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.
b6f6e18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage