@@ -32,7 +32,11 @@ export const decodeActiveDataFeedCountResponse = (
32
32
return activeDataFeedCount . toNumber ( ) ;
33
33
} ;
34
34
35
- export const decodeDataFeedDetails = ( dataFeed : string ) : DecodedDataFeed => {
35
+ export const decodeDataFeedDetails = ( dataFeed : string ) : DecodedDataFeed | null => {
36
+ // The contract returns empty bytes if the data feed is not registered. See:
37
+ // https://github.com/api3dao/dapi-management/blob/f3d39e4707c33c075a8f07aa8f8369f8dc07736f/contracts/AirseekerRegistry.sol#L209
38
+ if ( dataFeed === '0x' ) return null ;
39
+
36
40
if ( dataFeed . length === 130 ) {
37
41
// (64 [actual bytes] * 2[hex encoding] ) + 2 [for the '0x' preamble]
38
42
// This is a hex encoded string, the contract works with bytes directly
@@ -63,7 +67,7 @@ export interface DecodedUpdateParameters {
63
67
heartbeatInterval : ethers . BigNumber ;
64
68
}
65
69
66
- export const decodeUpdateParameters = ( updateParameters : string ) => {
70
+ export const decodeUpdateParameters = ( updateParameters : string ) : DecodedUpdateParameters => {
67
71
// https://github.com/api3dao/airnode-protocol-v1/blob/5f861715749e182e334c273d6a52c4f2560c7994/contracts/api3-server-v1/extensions/BeaconSetUpdatesWithPsp.sol#L122
68
72
const [ deviationThresholdInPercentage , deviationReference , heartbeatInterval ] = ethers . utils . defaultAbiCoder . decode (
69
73
[ 'uint256' , 'int224' , 'uint256' ] ,
@@ -77,17 +81,28 @@ export const decodeUpdateParameters = (updateParameters: string) => {
77
81
} ;
78
82
} ;
79
83
84
+ export interface DecodedActiveDataFeedResponse {
85
+ dapiName : string | null ;
86
+ decodedDapiName : string | null ;
87
+ decodedUpdateParameters : DecodedUpdateParameters ;
88
+ dataFeedValue : ethers . BigNumber ;
89
+ dataFeedTimestamp : number ;
90
+ decodedDataFeed : DecodedDataFeed ;
91
+ signedApiUrls : string [ ] ;
92
+ }
93
+
80
94
export const decodeActiveDataFeedResponse = (
81
95
airseekerRegistry : AirseekerRegistry ,
82
96
activeDataFeedReturndata : string
83
- ) => {
97
+ ) : DecodedActiveDataFeedResponse | null => {
84
98
const { dapiName, updateParameters, dataFeedValue, dataFeedTimestamp, dataFeedDetails, signedApiUrls } =
85
99
airseekerRegistry . interface . decodeFunctionResult ( 'activeDataFeed' , activeDataFeedReturndata ) as Awaited <
86
100
ReturnType < AirseekerRegistry [ 'activeDataFeed' ] >
87
101
> ;
88
102
89
- // https://github.com/api3dao/dapi-management/pull/3/files#diff-b6941851ebc92dc9691bbf0cb701fe9c4595cb78488c3bb92ad6e4b917719f4fR346
103
+ // https://github.com/api3dao/dapi-management/blob/f3d39e4707c33c075a8f07aa8f8369f8dc07736f/contracts/AirseekerRegistry.sol#L162
90
104
const decodedDataFeed = decodeDataFeedDetails ( dataFeedDetails ) ;
105
+ if ( ! decodedDataFeed ) return null ;
91
106
92
107
// The dAPI name will be set to zero (in bytes32) in case the data feed is not a dAPI and is identified by a data feed
93
108
// ID.
@@ -103,5 +118,3 @@ export const decodeActiveDataFeedResponse = (
103
118
signedApiUrls,
104
119
} ;
105
120
} ;
106
-
107
- export type DecodedActiveDataFeedResponse = ReturnType < typeof decodeActiveDataFeedResponse > ;
0 commit comments