Skip to content

Commit ab14efe

Browse files
authored
fix(docs): remove unstable calls to FTSO index (#500)
2 parents 9fc4b82 + f993cfb commit ab14efe

File tree

10 files changed

+103
-275
lines changed

10 files changed

+103
-275
lines changed

docs/ftso/solidity-reference/FtsoV2Interface.md

Lines changed: 3 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ description: Primary interface for interacting with FTSOv2.
77
import Remix from "@site/src/components/remix";
88
import CodeBlock from "@theme/CodeBlock";
99
import FTSOV2FeedById from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedById.sol";
10-
import FTSOV2FeedByIdWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIdWei.sol";
1110
import FTSOV2FeedByIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIndex.sol";
12-
import FTSOV2FeedByIndexWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIndexWei.sol";
13-
import FTSOV2FeedByIdIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIdIndex.sol";
11+
import FTSOV2FeedByIdWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIdWei.sol";
1412
import FTSOV2FeedsById from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsById.sol";
1513
import FTSOV2FeedsByIdWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIdWei.sol";
16-
import FTSOV2FeedsByIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIndex.sol";
1714
import FTSOV2FeedsByIndexWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIndexWei.sol";
1815
import FTSOV2VerifyProof from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2VerifyProof.sol";
1916

@@ -132,73 +129,6 @@ function getFeedByIndex(
132129
<Remix fileName="FTSOV2FeedByIndex.sol">Open sample in Remix</Remix>
133130
<br></br>
134131

135-
### getFeedByIndexInWei
136-
137-
Returns value in wei and timestamp of a feed.
138-
A fee (calculated by the FeeCalculator contract) may need to be paid.
139-
140-
```solidity
141-
function getFeedByIndexInWei(
142-
uint256 _index
143-
) external payable returns (
144-
uint256 _value,
145-
uint64 _timestamp
146-
);
147-
```
148-
149-
#### Parameters
150-
151-
- `_index`: The index of the feed, corresponding to feed id in the FastUpdatesConfiguration contract.
152-
153-
#### Returns
154-
155-
- `_value`: The value for the requested feed in wei (i.e. with 18 decimal places).
156-
- `_timestamp`: The timestamp of the last update.
157-
158-
<details>
159-
<summary>Sample contract usage</summary>
160-
161-
<CodeBlock language="solidity" title="FTSOV2FeedByIndexWei.sol">
162-
{FTSOV2FeedByIndexWei}
163-
</CodeBlock>
164-
165-
</details>
166-
167-
<Remix fileName="FTSOV2FeedByIndexWei.sol">Open sample in Remix</Remix>
168-
<br></br>
169-
170-
### getFeedId
171-
172-
Returns the feed id at a given index. Removed (unused) feed index will return bytes21(0).
173-
174-
```solidity
175-
function getFeedId(
176-
uint256 _index
177-
) external view returns (
178-
bytes21 _feedId
179-
);
180-
```
181-
182-
#### Parameters
183-
184-
- `_index`: The index.
185-
186-
#### Returns
187-
188-
- `_feedId`: The feed id.
189-
190-
<details>
191-
<summary>Sample contract usage</summary>
192-
193-
<CodeBlock language="solidity" title="FTSOV2FeedByIdIndex.sol">
194-
{FTSOV2FeedByIdIndex}
195-
</CodeBlock>
196-
197-
</details>
198-
199-
<Remix fileName="FTSOV2FeedByIdIndex.sol">Open sample in Remix</Remix>
200-
<br></br>
201-
202132
### getFeedIndex
203133

204134
Returns the index of a feed.
@@ -291,43 +221,6 @@ function getFeedsByIdInWei(
291221
<Remix fileName="FTSOV2FeedsByIdWei.sol">Open sample in Remix</Remix>
292222
<br></br>
293223

294-
### getFeedsByIndex
295-
296-
Returns stored data of each feed.
297-
A fee (calculated by the FeeCalculator contract) may need to be paid.
298-
299-
```solidity
300-
function getFeedsByIndex(
301-
uint256[] _indices
302-
) external payable returns (
303-
uint256[] _values,
304-
int8[] _decimals,
305-
uint64 _timestamp
306-
);
307-
```
308-
309-
#### Parameters
310-
311-
- `_indices`: Indices of the feeds, corresponding to feed ids in the FastUpdatesConfiguration contract.
312-
313-
#### Returns
314-
315-
- `_values`: The list of values for the requested feeds.
316-
- `_decimals`: The list of decimal places for the requested feeds.
317-
- `_timestamp`: The timestamp of the last update.
318-
319-
<details>
320-
<summary>Sample contract usage</summary>
321-
322-
<CodeBlock language="solidity" title="FTSOV2FeedsByIndex.sol">
323-
{FTSOV2FeedsByIndex}
324-
</CodeBlock>
325-
326-
</details>
327-
328-
<Remix fileName="FTSOV2FeedsByIndex.sol">Open sample in Remix</Remix>
329-
<br></br>
330-
331224
### getFeedsByIndexInWei
332225

333226
Returns value in wei of each feed and a timestamp.
@@ -417,7 +310,7 @@ Feed data with proof structure
417310

418311
```solidity
419312
struct FeedDataWithProof {
420-
bytes32[] proof;
421-
struct FtsoV2Interface.FeedData body;
313+
bytes32[] proof;
314+
struct FtsoV2Interface.FeedData body;
422315
}
423316
```

examples/developer-hub-solidity/FTSOV2FeedById.sol

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,8 @@ import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/costo
1212
contract FtsoV2FeedConsumerById {
1313
TestFtsoV2Interface internal ftsoV2;
1414
// Example Feed ID for FLR/USD
15-
bytes21 public feedId = bytes21(0x01464c522f55534400000000000000000000000000); // FLR/USD
16-
17-
/**
18-
* Constructor initializes the FTSOv2 contract.
19-
* The contract registry is used to fetch the FtsoV2 contract address.
20-
*/
21-
constructor() {
22-
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
23-
ftsoV2 = ContractRegistry.getTestFtsoV2();
24-
}
15+
bytes21 public feedId =
16+
bytes21(0x01464c522f55534400000000000000000000000000); // FLR/USD
2517

2618
/**
2719
* Get the current value of a specific feed by its ID.
@@ -30,15 +22,13 @@ contract FtsoV2FeedConsumerById {
3022
* @return _timestamp The timestamp of the last feed update.
3123
*/
3224
function getFtsoV2FeedValueById()
33-
external
34-
payable
35-
returns (
36-
uint256 _feedValue,
37-
int8 _decimals,
38-
uint64 _timestamp
39-
)
25+
external
26+
payable
27+
returns (uint256 _feedValue, int8 _decimals, uint64 _timestamp)
4028
{
29+
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
30+
ftsoV2 = ContractRegistry.getTestFtsoV2();
4131
/* Retrieves the latest value, decimals, and timestamp for the specified feed ID. */
4232
return ftsoV2.getFeedById(feedId);
4333
}
44-
}
34+
}

examples/developer-hub-solidity/FTSOV2FeedByIdWei.sol

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,28 @@ import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/costo
1111
*/
1212
contract FtsoV2FeedTracker {
1313
TestFtsoV2Interface internal ftsoV2;
14-
15-
// Feed data structure to store multiple feed values with timestamps
16-
struct FeedInfo {
17-
uint256 valueInWei;
18-
uint64 timestamp;
19-
}
20-
21-
// Mapping to store the latest feed data for a given index
22-
mapping(uint256 => FeedInfo) public feedDataByIndex;
23-
uint256 public highestValueIndex;
24-
uint256 public highestValueInWei;
14+
bytes21 public feedId = bytes21(0x01464c522f55534400000000000000000000000000); // FLR/USD
2515

2616
// Event to track feed retrieval
27-
event FeedFetched(uint256 index, uint256 valueInWei, uint64 timestamp);
28-
29-
/**
30-
* Constructor initializes the FTSOv2 contract.
31-
* The contract registry is used to fetch the FtsoV2 contract address.
32-
*/
33-
constructor() {
34-
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
35-
ftsoV2 = ContractRegistry.getTestFtsoV2();
36-
}
17+
event FeedFetched(bytes21 feedId, uint256 valueInWei, uint64 timestamp);
3718

3819
/**
3920
* Get the current value of a specific feed by its index, in wei.
40-
* @param _index The index of the feed to retrieve.
4121
* @return _feedValue The latest price value of the feed in wei.
4222
* @return _timestamp The timestamp of the last update for the feed.
4323
*/
44-
function getFeedValueByIndexInWei(uint256 _index)
45-
external
46-
payable
47-
returns (uint256 _feedValue, uint64 _timestamp)
24+
function getFeedValueByIdWei()
25+
external
26+
payable
27+
returns (uint256 _feedValue, uint64 _timestamp)
4828
{
29+
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
30+
ftsoV2 = ContractRegistry.getTestFtsoV2();
4931
// Retrieve feed value and timestamp from the FtsoV2 contract
50-
(_feedValue, _timestamp) = ftsoV2.getFeedByInWei{value: msg.value}(_index);
51-
52-
// Store the feed value and timestamp in the contract's storage
53-
feedDataByIndex[_index] = FeedInfo({
54-
valueInWei: _feedValue,
55-
timestamp: _timestamp
56-
});
57-
58-
// Update the highest value feed if applicable
59-
if (_feedValue > highestValueInWei) {
60-
highestValueInWei = _feedValue;
61-
highestValueIndex = _index;
62-
}
32+
(_feedValue, _timestamp) = ftsoV2.getFeedByIdInWei(feedId);
6333

6434
// Emit an event to log the feed retrieval
65-
emit FeedFetched(_index, _feedValue, _timestamp);
35+
emit FeedFetched(feedId, _feedValue, _timestamp);
6636
}
6737

6838
}

examples/developer-hub-solidity/FTSOV2FeedByIndex.sol

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,21 @@ contract FtsoV2FeedConsumerByIndex {
1414
// Example index for a feed (corresponding to a feed id)
1515
uint256 public feedIndex = 1; // Example: FLR/USD
1616

17-
/**
18-
* Constructor initializes the FTSOv2 contract.
19-
* The contract registry is used to fetch the FtsoV2 contract address.
20-
*/
21-
constructor() {
22-
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
23-
ftsoV2 = ContractRegistry.getTestFtsoV2();
24-
}
25-
2617
/**
2718
* Get the current value of a specific feed by its index.
2819
* @return _feedValue The latest price value of the feed.
2920
* @return _decimals The decimal precision of the feed value.
3021
* @return _timestamp The timestamp of the last feed update.
3122
*/
3223
function getFtsoV2FeedValueByIndex()
33-
external
34-
payable
35-
returns (
36-
uint256 _feedValue,
37-
int8 _decimals,
38-
uint64 _timestamp
39-
)
24+
external
25+
payable
26+
returns (uint256 _feedValue, int8 _decimals, uint64 _timestamp)
4027
{
28+
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
29+
ftsoV2 = ContractRegistry.getTestFtsoV2();
30+
4131
/* Retrieves the latest value, decimals, and timestamp for the specified feed index. */
4232
return ftsoV2.getFeedByIndex(feedIndex);
4333
}
44-
}
34+
}

examples/developer-hub-solidity/FTSOV2FeedsById.sol

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,25 @@ contract FtsoV2FeedConsumer {
1313
TestFtsoV2Interface internal ftsoV2;
1414
// Feed IDs, see https://dev.flare.network/ftso/feeds for full list
1515
bytes21[] public feedIds = [
16-
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
17-
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
18-
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
16+
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
17+
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
18+
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
1919
];
2020

21-
/**
22-
* Constructor initializes the FTSOv2 contract.
23-
* The contract registry is used to fetch the FtsoV2 contract address.
24-
*/
25-
constructor() {
26-
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
27-
ftsoV2 = ContractRegistry.getTestFtsoV2();
28-
}
29-
3021
/**
3122
* Get the current value of the feeds.
3223
*/
3324
function getFtsoV2CurrentFeedValues()
34-
external
35-
view
36-
returns (
37-
uint256[] memory _feedValues,
38-
int8[] memory _decimals,
39-
uint64 _timestamp
40-
)
25+
external
26+
returns (
27+
uint256[] memory _feedValues,
28+
int8[] memory _decimals,
29+
uint64 _timestamp
30+
)
4131
{
32+
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
33+
ftsoV2 = ContractRegistry.getTestFtsoV2();
4234
/* Your custom feed consumption logic. In this example the values are just returned. */
4335
return ftsoV2.getFeedsById(feedIds);
4436
}
45-
}
37+
}

examples/developer-hub-solidity/FTSOV2FeedsByIdWei.sol

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,17 @@ contract FtsoV2FeedConsumer {
1414

1515
// Feed IDs, see https://dev.flare.network/ftso/feeds for full list
1616
bytes21[] public feedIds = [
17-
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
18-
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
19-
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
17+
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
18+
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
19+
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
2020
];
2121

2222
// Event to log feed values retrieval
23-
event FeedValuesRetrieved(bytes21[] indexed feedIds, uint256[] values, uint64 timestamp);
24-
25-
/**
26-
* Constructor initializes the FTSOv2 contract.
27-
* The contract registry is used to fetch the FtsoV2 contract address.
28-
*/
29-
constructor() {
30-
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
31-
ftsoV2 = ContractRegistry.getTestFtsoV2();
32-
}
23+
event FeedValuesRetrieved(
24+
bytes21[] indexed feedIds,
25+
uint256[] values,
26+
uint64 timestamp
27+
);
3328

3429
/**
3530
* Get the current value of the feeds in wei.
@@ -38,18 +33,19 @@ contract FtsoV2FeedConsumer {
3833
* @return _values The list of values for the requested feeds in wei.
3934
* @return _timestamp The timestamp of the last update.
4035
*/
41-
function getFeedsByIdInWei(bytes21[] calldata _feedIds)
42-
external
43-
payable
44-
returns (uint256[] memory _values, uint64 _timestamp)
45-
{
36+
function getFeedsByIdInWei(
37+
bytes21[] calldata _feedIds
38+
) external payable returns (uint256[] memory _values, uint64 _timestamp) {
4639
// Ensure that the length of the feed IDs is non-zero
4740
require(_feedIds.length > 0, "No feed IDs provided");
4841

42+
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
43+
ftsoV2 = ContractRegistry.getTestFtsoV2();
44+
4945
// Retrieve the feed values and timestamp from the FTSOv2 contract
5046
(_values, _timestamp) = ftsoV2.getFeedsByIdInWei(_feedIds);
5147

5248
// Emit an event to log the retrieved feed values
5349
emit FeedValuesRetrieved(_feedIds, _values, _timestamp);
5450
}
55-
}
51+
}

0 commit comments

Comments
 (0)