|
1 |
| -import type { Infer } from '@metamask/superstruct'; |
2 |
| -import { |
3 |
| - number, |
4 |
| - object, |
5 |
| - string, |
6 |
| - optional, |
7 |
| - record, |
8 |
| - nullable, |
9 |
| -} from '@metamask/superstruct'; |
10 |
| -import { CaipAssetTypeStruct, type CaipAssetType } from '@metamask/utils'; |
| 1 | +import { type CaipAssetType } from '@metamask/utils'; |
11 | 2 |
|
12 |
| -export const AssetConversionStruct = object({ |
13 |
| - rate: string(), |
14 |
| - conversionTime: number(), |
15 |
| - expirationTime: optional(number()), |
16 |
| -}); |
17 |
| - |
18 |
| -export const OnAssetsConversionResponseStruct = object({ |
19 |
| - conversionRates: record( |
20 |
| - CaipAssetTypeStruct, |
21 |
| - record(CaipAssetTypeStruct, nullable(AssetConversionStruct)), |
22 |
| - ), |
23 |
| -}); |
| 3 | +/** |
| 4 | + * The market data for an asset. |
| 5 | + * |
| 6 | + * @property marketCap - The market capitalization of the asset. |
| 7 | + * @property totalVolume - The total volume of the asset. |
| 8 | + * @property circulatingSupply - The circulating supply of the asset. |
| 9 | + * @property allTimeHigh - The all-time high price of the asset. |
| 10 | + * @property allTimeLow - The all-time low price of the asset. |
| 11 | + * @property pricePercentChange - The percentage change in price over different intervals. |
| 12 | + * @property pricePercentChange.interval - The time interval for the price change as a ISO 8601 duration |
| 13 | + * or the string "all" to represent the all-time change. |
| 14 | + */ |
| 15 | +export type MarketData = { |
| 16 | + marketCap: string; |
| 17 | + totalVolume: string; |
| 18 | + circulatingSupply: string; |
| 19 | + allTimeHigh: string; |
| 20 | + allTimeLow: string; |
| 21 | + pricePercentChange: { |
| 22 | + [interval: string]: number; |
| 23 | + }; |
| 24 | +}; |
24 | 25 |
|
25 |
| -export type AssetConversion = Infer<typeof AssetConversionStruct>; |
| 26 | +/** |
| 27 | + * The conversion rate between two assets. |
| 28 | + * |
| 29 | + * @property rate - The conversion rate between the two assets. |
| 30 | + * @property marketData - The market data for the asset, if requested. |
| 31 | + * @property conversionTime - The time at which the conversion rate was calculated. |
| 32 | + * @property expirationTime - The time at which the conversion rate expires. |
| 33 | + */ |
| 34 | +export type AssetConversion = { |
| 35 | + rate: string; |
| 36 | + marketData?: MarketData; |
| 37 | + conversionTime: number; |
| 38 | + expirationTime?: number; |
| 39 | +}; |
26 | 40 |
|
| 41 | +/** |
| 42 | + * The arguments for the `onAssetsConversion` handler. |
| 43 | + * |
| 44 | + * @property conversions - An array of objects containing the `from` and `to` asset types. |
| 45 | + * @property includeMarketData - Whether to include market data in the response. |
| 46 | + */ |
27 | 47 | export type OnAssetsConversionArguments = {
|
28 | 48 | conversions: { from: CaipAssetType; to: CaipAssetType }[];
|
| 49 | + includeMarketData?: boolean; |
29 | 50 | };
|
30 | 51 |
|
31 | 52 | /**
|
32 | 53 | * The `onAssetsConversion` handler. This is called by MetaMask when querying about asset conversion on specific chains.
|
33 | 54 | *
|
| 55 | + * @param args - The arguments for the handler. |
| 56 | + * see {@link OnAssetsConversionArguments}. |
34 | 57 | * @returns The conversion for each asset. See
|
35 | 58 | * {@link OnAssetsConversionResponse}.
|
36 | 59 | */
|
|
0 commit comments