11import { priceFeedScope } from '.' ;
22import { getDeployedContract } from './utils' ;
33
4- // Common token IDs used in testing - update this as needed
5- const KNOWN_TOKEN_IDS = [
6- '21742633143463906290569050155826241533067272736897614950488156847949938836455' ,
7- '21742633143463906290569050155826241533067272736897614950488156847949938836456'
8- ] ;
9-
104/**
115 * Task: Fetches the latest answers from the PriceFeed contract.
126 * Optional parameters:
137 * - contract: PriceFeed contract address
14- * - tokenId: Specific Polymarket token ID to fetch (if not provided, shows all prices)
8+ * - tokenId: Specific token ID to fetch (if not provided, shows all prices)
159 * - tokenIndex: Specific token index to fetch (if not provided, shows all prices)
1610 * If the contract address is not provided, fetches from previous deployments.
1711 */
1812priceFeedScope
19- . task ( 'latest' , 'Calls the latestAnswer function on the PriceFeed contract' )
13+ . task ( 'latest' , 'Fetches the latest prices from the PriceFeed contract' )
2014 . addOptionalParam ( 'contract' , 'The PriceFeed contract address' )
21- . addOptionalParam ( 'tokenId' , 'Specific Polymarket token ID to fetch' )
15+ . addOptionalParam ( 'tokenId' , 'Specific token ID to fetch' )
2216 . addOptionalParam ( 'tokenIndex' , 'Specific token index to fetch' )
2317 . setAction ( async ( { contract, tokenId, tokenIndex } , hre ) => {
2418 try {
@@ -42,30 +36,36 @@ priceFeedScope
4236 console . log ( 'Could not update latest answers. Using cached data if available.\n' ) ;
4337 }
4438
45- // Handle tokenId parameter by finding its index in known token IDs
46- let targetIndex = tokenIndex ;
39+ // Handle tokenId parameter using direct lookup
4740 if ( tokenId !== undefined ) {
48- const foundIndex = KNOWN_TOKEN_IDS . findIndex ( id => id === tokenId ) ;
49- if ( foundIndex === - 1 ) {
50- console . error ( `Token ID ${ tokenId } not found in known token IDs. Known token IDs:` ) ;
51- KNOWN_TOKEN_IDS . forEach ( ( id , index ) => {
52- console . log ( ` Index ${ index } : ${ id } ` ) ;
53- } ) ;
41+ try {
42+ // Use generic contract call since TypeScript interface might not be updated yet
43+ const price = await priceFeed . getFunction ( 'getPriceByTokenId' ) ( tokenId ) ;
44+ console . log ( `Price for token ID ${ tokenId } : ${ price . toString ( ) } ` ) ;
45+ return ;
46+ } catch ( error ) {
47+ console . error ( `Error getting price for token ID ${ tokenId } : ${ error } ` ) ;
48+ try {
49+ const allTokenIds = await priceFeed . getAllTokenIds ( ) ;
50+ console . log ( 'Available token IDs:' ) ;
51+ allTokenIds . forEach ( ( id , index ) => {
52+ console . log ( ` Index ${ index } : ${ id } ` ) ;
53+ } ) ;
54+ } catch ( listError ) {
55+ console . log ( 'Could not retrieve available token IDs' ) ;
56+ }
5457 return ;
5558 }
56- targetIndex = foundIndex . toString ( ) ;
5759 }
5860
59- if ( targetIndex !== undefined ) {
60- // Fetch specific token price
61- const price = await priceFeed . getPrice ( targetIndex ) ;
62-
63- // Show token ID if we know it
64- const knownTokenId = KNOWN_TOKEN_IDS [ parseInt ( targetIndex ) ] ;
65- if ( knownTokenId ) {
66- console . log ( `Price for token ID ${ knownTokenId } (index ${ targetIndex } ): ${ price . toString ( ) } ` ) ;
67- } else {
68- console . log ( `Price for token index ${ targetIndex } : ${ price . toString ( ) } ` ) ;
61+ if ( tokenIndex !== undefined ) {
62+ // Fetch specific token price by index
63+ const price = await priceFeed . getPrice ( tokenIndex ) ;
64+ try {
65+ const tokenIdDisplay = await priceFeed . getTokenId ( tokenIndex ) ;
66+ console . log ( `Price for token ID ${ tokenIdDisplay } (index ${ tokenIndex } ): ${ price . toString ( ) } ` ) ;
67+ } catch ( error ) {
68+ console . log ( `Price for token index ${ tokenIndex } : ${ price . toString ( ) } ` ) ;
6969 }
7070 } else {
7171 // Fetch all prices
@@ -75,21 +75,21 @@ priceFeedScope
7575
7676 console . log ( `\nToken Count: ${ tokenCount . toString ( ) } ` ) ;
7777 console . log ( 'All Prices:' ) ;
78- allPrices . forEach ( ( price , index ) => {
79- const knownTokenId = KNOWN_TOKEN_IDS [ index ] ;
80- if ( knownTokenId ) {
81- console . log ( ` Token ID ${ knownTokenId } (index ${ index } ): ${ price . toString ( ) } ` ) ;
82- } else {
83- console . log ( ` Token index ${ index } : ${ price . toString ( ) } ` ) ;
84- }
85- } ) ;
8678
87- // Also show legacy latestAnswer for backward compatibility
8879 try {
89- const legacyAnswer = await priceFeed . latestAnswer ( ) ;
90- console . log ( `\nLegacy Latest Answer (first price): ${ legacyAnswer . toString ( ) } ` ) ;
80+ const allTokenIds = await priceFeed . getAllTokenIds ( ) ;
81+ console . log ( `Found ${ allTokenIds . length } stored token IDs` ) ;
82+ allPrices . forEach ( ( price , index ) => {
83+ const tokenId = allTokenIds [ index ] || `index-${ index } ` ;
84+ console . log ( ` Token ID ${ tokenId } (index ${ index } ): ${ price . toString ( ) } ` ) ;
85+ } ) ;
9186 } catch ( error ) {
92- console . log ( '\nLegacy Latest Answer: Not available' ) ;
87+ console . log ( `Error getting token IDs: ${ error } ` ) ;
88+ console . log ( 'Fallback to index-based display' ) ;
89+ // Fallback to index-based display if token IDs not available
90+ allPrices . forEach ( ( price , index ) => {
91+ console . log ( ` Token index ${ index } : ${ price . toString ( ) } ` ) ;
92+ } ) ;
9393 }
9494 }
9595 } catch ( error : unknown ) {
0 commit comments