Skip to content

Commit 50776b2

Browse files
Version 0.1.22
1 parent c84af6b commit 50776b2

File tree

14 files changed

+426
-320
lines changed

14 files changed

+426
-320
lines changed

coston/FtsoV2Interface.sol

Lines changed: 41 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,46 @@ interface FtsoV2Interface {
2121
FeedData body;
2222
}
2323

24+
/// Feed id change structure
25+
struct FeedIdChange {
26+
bytes21 oldFeedId;
27+
bytes21 newFeedId;
28+
}
29+
30+
/// Event emitted when a feed id is changed (e.g. feed renamed).
31+
event FeedIdChanged(bytes21 indexed oldFeedId, bytes21 indexed newFeedId);
32+
2433
/**
25-
* Returns stored data of a feed.
26-
* A fee (calculated by the FeeCalculator contract) may need to be paid.
27-
* @param _index The index of the feed, corresponding to feed id in
28-
* the FastUpdatesConfiguration contract.
29-
* @return _value The value for the requested feed.
30-
* @return _decimals The decimal places for the requested feed.
31-
* @return _timestamp The timestamp of the last update.
34+
* Returns the FTSO protocol id.
3235
*/
33-
function getFeedByIndex(uint256 _index)
34-
external payable
35-
returns (
36-
uint256 _value,
37-
int8 _decimals,
38-
uint64 _timestamp
39-
);
36+
function getFtsoProtocolId() external view returns (uint256);
37+
38+
/**
39+
* Returns the list of supported feed ids (currently active feed ids).
40+
* To get the list of all available feed ids, combine with `getFeedIdChanges()`.
41+
* @return _feedIds The list of supported feed ids.
42+
*/
43+
function getSupportedFeedIds() external view returns (bytes21[] memory _feedIds);
44+
45+
/**
46+
* Returns the list of feed id changes.
47+
* @return _feedIdChanges The list of changed feed id pairs (old and new feed id).
48+
*/
49+
function getFeedIdChanges() external view returns (FeedIdChange[] memory _feedIdChanges);
50+
51+
/**
52+
* Calculates the fee for fetching a feed.
53+
* @param _feedId The id of the feed.
54+
* @return _fee The fee for fetching the feed.
55+
*/
56+
function calculateFeeById(bytes21 _feedId) external view returns (uint256 _fee);
57+
58+
/**
59+
* Calculates the fee for fetching feeds.
60+
* @param _feedIds The list of feed ids.
61+
* @return _fee The fee for fetching the feeds.
62+
*/
63+
function calculateFeeByIds(bytes21[] memory _feedIds) external view returns (uint256 _fee);
4064

4165
/**
4266
* Returns stored data of a feed.
@@ -54,23 +78,6 @@ interface FtsoV2Interface {
5478
uint64 _timestamp
5579
);
5680

57-
/**
58-
* Returns stored data of each feed.
59-
* A fee (calculated by the FeeCalculator contract) may need to be paid.
60-
* @param _indices Indices of the feeds, corresponding to feed ids in
61-
* the FastUpdatesConfiguration contract.
62-
* @return _values The list of values for the requested feeds.
63-
* @return _decimals The list of decimal places for the requested feeds.
64-
* @return _timestamp The timestamp of the last update.
65-
*/
66-
function getFeedsByIndex(uint256[] calldata _indices)
67-
external payable
68-
returns (
69-
uint256[] memory _values,
70-
int8[] memory _decimals,
71-
uint64 _timestamp
72-
);
73-
7481
/**
7582
* Returns stored data of each feed.
7683
* A fee (calculated by the FeeCalculator contract) may need to be paid.
@@ -79,31 +86,14 @@ interface FtsoV2Interface {
7986
* @return _decimals The list of decimal places for the requested feeds.
8087
* @return _timestamp The timestamp of the last update.
8188
*/
82-
function getFeedsById(bytes21[] calldata _feedIds)
89+
function getFeedsById(bytes21[] memory _feedIds)
8390
external payable
8491
returns (
8592
uint256[] memory _values,
8693
int8[] memory _decimals,
8794
uint64 _timestamp
8895
);
8996

90-
/**
91-
* Returns value in wei and timestamp of a feed.
92-
* A fee (calculated by the FeeCalculator contract) may need to be paid.
93-
* @param _index The index of the feed, corresponding to feed id in
94-
* the FastUpdatesConfiguration contract.
95-
* @return _value The value for the requested feed in wei (i.e. with 18 decimal places).
96-
* @return _timestamp The timestamp of the last update.
97-
*/
98-
function getFeedByIndexInWei(
99-
uint256 _index
100-
)
101-
external payable
102-
returns (
103-
uint256 _value,
104-
uint64 _timestamp
105-
);
106-
10797
/**
10898
* Returns value in wei and timestamp of a feed.
10999
* A fee (calculated by the FeeCalculator contract) may need to be paid.
@@ -118,51 +108,23 @@ interface FtsoV2Interface {
118108
uint64 _timestamp
119109
);
120110

121-
/** Returns value in wei of each feed and a timestamp.
122-
* For some feeds, a fee (calculated by the FeeCalculator contract) may need to be paid.
123-
* @param _indices Indices of the feeds, corresponding to feed ids in
124-
* the FastUpdatesConfiguration contract.
125-
* @return _values The list of values for the requested feeds in wei (i.e. with 18 decimal places).
126-
* @return _timestamp The timestamp of the last update.
127-
*/
128-
function getFeedsByIndexInWei(uint256[] calldata _indices)
129-
external payable
130-
returns (
131-
uint256[] memory _values,
132-
uint64 _timestamp
133-
);
134-
135111
/** Returns value of each feed and a timestamp.
136112
* For some feeds, a fee (calculated by the FeeCalculator contract) may need to be paid.
137113
* @param _feedIds Ids of the feeds.
138114
* @return _values The list of values for the requested feeds in wei (i.e. with 18 decimal places).
139115
* @return _timestamp The timestamp of the last update.
140116
*/
141-
function getFeedsByIdInWei(bytes21[] calldata _feedIds)
117+
function getFeedsByIdInWei(bytes21[] memory _feedIds)
142118
external payable
143119
returns (
144120
uint256[] memory _values,
145121
uint64 _timestamp
146122
);
147123

148-
/**
149-
* Returns the index of a feed.
150-
* @param _feedId The feed id.
151-
* @return _index The index of the feed.
152-
*/
153-
function getFeedIndex(bytes21 _feedId) external view returns (uint256 _index);
154-
155-
/**
156-
* Returns the feed id at a given index. Removed (unused) feed index will return bytes21(0).
157-
* @param _index The index.
158-
* @return _feedId The feed id.
159-
*/
160-
function getFeedId(uint256 _index) external view returns (bytes21 _feedId);
161-
162124
/**
163125
* Checks if the feed data is valid (i.e. is part of the confirmed Merkle tree).
164126
* @param _feedData Structure containing data about the feed (FeedData structure) and Merkle proof.
165127
* @return true if the feed data is valid.
166128
*/
167129
function verifyFeedData(FeedDataWithProof calldata _feedData) external view returns (bool);
168-
}
130+
}

coston/IFdcVerification.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "./IConfirmedBlockHeightExistsVerification.sol";
77
import "./IEVMTransactionVerification.sol";
88
import "./IPaymentVerification.sol";
99
import "./IReferencedPaymentNonexistenceVerification.sol";
10+
import "./IWeb2JsonVerification.sol";
1011

1112

1213
/**
@@ -18,5 +19,6 @@ interface IFdcVerification is
1819
IConfirmedBlockHeightExistsVerification,
1920
IEVMTransactionVerification,
2021
IPaymentVerification,
21-
IReferencedPaymentNonexistenceVerification
22+
IReferencedPaymentNonexistenceVerification,
23+
IWeb2JsonVerification
2224
{ }

coston/IWeb2Json.sol

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.7.6 <0.9;
3+
4+
/**
5+
* @custom:name IWeb2Json
6+
* @custom:supported WEB2
7+
* @author Flare
8+
* @notice An attestation request that fetches JSON data from the given URL,
9+
* applies a jq filter to transform the returned result, and returns the structured data as ABI encoded data.
10+
* @custom:verification Data is fetched from an URL `url`. The received data is then processed with jq as
11+
* the `postProcessJq` states. The structure of the final JSON is written in the `abiSignature`.
12+
*
13+
* The response contains an abi encoding of the final data.
14+
* @custom:lut `0xffffffffffffffff`
15+
* @custom:lut-limit `0xffffffffffffffff`
16+
*/
17+
interface IWeb2Json {
18+
/**
19+
* @notice Toplevel request
20+
* @param attestationType ID of the attestation type.
21+
* @param sourceId ID of the data source.
22+
* @param messageIntegrityCode `MessageIntegrityCode` that is derived from the expected response.
23+
* @param requestBody Data defining the request. Type (struct) and interpretation is determined
24+
* by the `attestationType`.
25+
*/
26+
struct Request {
27+
bytes32 attestationType;
28+
bytes32 sourceId;
29+
bytes32 messageIntegrityCode;
30+
RequestBody requestBody;
31+
}
32+
33+
/**
34+
* @notice Toplevel response
35+
* @param attestationType Extracted from the request.
36+
* @param sourceId Extracted from the request.
37+
* @param votingRound The ID of the State Connector round in which the request was considered.
38+
* @param lowestUsedTimestamp The lowest timestamp used to generate the response.
39+
* @param requestBody Extracted from the request.
40+
* @param responseBody Data defining the response. The verification rules for the construction
41+
* of the response body and the type are defined per specific `attestationType`.
42+
*/
43+
struct Response {
44+
bytes32 attestationType;
45+
bytes32 sourceId;
46+
uint64 votingRound;
47+
uint64 lowestUsedTimestamp;
48+
RequestBody requestBody;
49+
ResponseBody responseBody;
50+
}
51+
52+
/**
53+
* @notice Toplevel proof
54+
* @param merkleProof Merkle proof corresponding to the attestation response.
55+
* @param data Attestation response.
56+
*/
57+
struct Proof {
58+
bytes32[] merkleProof;
59+
Response data;
60+
}
61+
62+
/**
63+
* @notice Request body for Web2Json attestation type
64+
* @param url URL of the data source
65+
* @param httpMethod HTTP method to be used to fetch from URL source.
66+
* Supported methods: GET, POST, PUT, PATCH, DELETE.
67+
* @param headers Headers to be included to fetch from URL source. Use `{}` if no headers are needed.
68+
* @param queryParams Query parameters to be included to fetch from URL source.
69+
* Use `{}` if no query parameters are needed.
70+
* @param body Request body to be included to fetch from URL source. Use '{}' if no request body is required.
71+
* @param postProcessJq jq filter used to post-process the JSON response from the URL.
72+
* @param abiSignature ABI signature of the struct used to encode the data after jq post-processing.
73+
*/
74+
struct RequestBody {
75+
string url;
76+
string httpMethod;
77+
string headers;
78+
string queryParams;
79+
string body;
80+
string postProcessJq;
81+
string abiSignature;
82+
}
83+
84+
/**
85+
* @notice Response body for Web2Json attestation type
86+
* @param abiEncodedData Raw binary data encoded to match the function parameters in ABI.
87+
*/
88+
struct ResponseBody {
89+
bytes abiEncodedData;
90+
}
91+
}

coston/IWeb2JsonVerification.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.7.6 <0.9;
3+
4+
import "./IWeb2Json.sol";
5+
6+
interface IWeb2JsonVerification {
7+
function verifyJsonApi(IWeb2Json.Proof calldata _proof) external view returns (bool _proved);
8+
}

0 commit comments

Comments
 (0)