Skip to content

Commit eeead49

Browse files
committed
fix(docs): correct the calls in the smart contract
1 parent d7d34eb commit eeead49

File tree

9 files changed

+105
-138
lines changed

9 files changed

+105
-138
lines changed

docs/ftso/solidity-reference/FtsoV2Interface.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ 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";
10+
//import FTSOV2FeedByIdWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIdWei.sol";
1111
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";
12+
//import FTSOV2FeedByIndexWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIndexWei.sol";
13+
//import FTSOV2FeedByIdIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIdIndex.sol";
1414
import FTSOV2FeedsById from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsById.sol";
1515
import FTSOV2FeedsByIdWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIdWei.sol";
16-
import FTSOV2FeedsByIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIndex.sol";
17-
import FTSOV2FeedsByIndexWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIndexWei.sol";
16+
//import FTSOV2FeedsByIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIndex.sol";
17+
//import FTSOV2FeedsByIndexWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIndexWei.sol";
1818
import FTSOV2VerifyProof from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2VerifyProof.sol";
1919

2020
Primary interface for interacting with FTSOv2. This is a long-term support (LTS) interface, designed to ensure continuity even as underlying contracts evolve or protocols migrate to new versions.
@@ -371,7 +371,7 @@ Checks if the feed data is valid (i.e. is part of the confirmed Merkle tree).
371371
function verifyFeedData(
372372
struct FtsoV2Interface.FeedDataWithProof _feedData
373373
) external view returns (
374-
bool
374+
bool
375375
);
376376
```
377377

@@ -403,11 +403,11 @@ Feed data structure
403403

404404
```solidity
405405
struct FeedData {
406-
uint32 votingRoundId;
407-
bytes21 id;
408-
int32 value;
409-
uint16 turnoutBIPS;
410-
int8 decimals;
406+
uint32 votingRoundId;
407+
bytes21 id;
408+
int32 value;
409+
uint16 turnoutBIPS;
410+
int8 decimals;
411411
}
412412
```
413413

@@ -417,7 +417,7 @@ Feed data with proof structure
417417

418418
```solidity
419419
struct FeedDataWithProof {
420-
bytes32[] proof;
421-
struct FtsoV2Interface.FeedData body;
420+
bytes32[] proof;
421+
struct FtsoV2Interface.FeedData body;
422422
}
423423
```

examples/developer-hub-solidity/FTSOV2FeedById.sol

Lines changed: 10 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,15 @@ 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
{
4129
/* Retrieves the latest value, decimals, and timestamp for the specified feed ID. */
30+
31+
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
32+
ftsoV2 = ContractRegistry.getTestFtsoV2();
33+
4234
return ftsoV2.getFeedById(feedId);
4335
}
44-
}
36+
}

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+
}

examples/developer-hub-solidity/FtsoV2AnchorFeedConsumer.sol

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ pragma solidity >=0.8.0 <0.9.0;
33

44
import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol";
55
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
6+
import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";
67

78
/**
89
* THIS IS AN EXAMPLE CONTRACT.
910
* DO NOT USE THIS CODE IN PRODUCTION.
1011
*/
1112
contract FtsoV2AnchorFeedConsumer {
12-
mapping(uint32 => mapping(bytes21 => FtsoV2Interface.FeedData))
13-
public provenFeeds;
13+
TestFtsoV2Interface internal ftsoV2;
14+
mapping(uint32 => mapping(bytes21 => TestFtsoV2Interface.FeedData))
15+
public provenFeeds;
1416

15-
function savePrice(FtsoV2Interface.FeedDataWithProof calldata data) public {
17+
function savePrice(
18+
TestFtsoV2Interface.FeedDataWithProof calldata data
19+
) public {
20+
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
21+
ftsoV2 = ContractRegistry.getTestFtsoV2();
1622
// Step 1: Verify the proof
17-
require(
18-
ContractRegistry.getFtsoV2().verifyFeedData(data),
19-
"Invalid proof"
20-
);
23+
require(ftsoV2.verifyFeedData(data), "Invalid proof");
2124
// Step 2: Use the feed data with app specific logic
2225
// Here the feeds are saved
2326
provenFeeds[data.body.votingRoundId][data.body.id] = data.body;

examples/developer-hub-solidity/FtsoV2ChangeQuoteFeed.sol

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/costo
1212
contract FtsoV2ChangeQuoteFeed {
1313
TestFtsoV2Interface internal ftsoV2;
1414

15-
/**
16-
* Initializing an instance with FtsoV2Interface.
17-
* The contract registry is used to fetch the contract address.
18-
*/
19-
constructor() {
20-
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
21-
ftsoV2 = ContractRegistry.getTestFtsoV2();
22-
}
23-
2415
/**
2516
* @dev Internal function to scale the base feed value to match the decimals of the final feed.
2617
*/
@@ -52,11 +43,13 @@ contract FtsoV2ChangeQuoteFeed {
5243
*/
5344
function getNewQuoteFeedValue(
5445
bytes21[] calldata _baseAndQuoteFeedIds
55-
) external view returns (uint256) {
46+
) external returns (uint256) {
5647
require(
5748
_baseAndQuoteFeedIds.length == 2,
5849
"Invalid feed indexes. Please provide exactly two indexes."
5950
);
51+
52+
ftsoV2 = ContractRegistry.getTestFtsoV2();
6053
// Fetch current feeds
6154
(uint256[] memory feedValues, int8[] memory decimals, ) = ftsoV2
6255
.getFeedsById(_baseAndQuoteFeedIds);
@@ -92,6 +85,7 @@ contract FtsoV2ChangeQuoteFeed {
9285
_baseAndQuoteFeedIds.length == 2,
9386
"Invalid feed indexes. Please provide exactly two indexes."
9487
);
88+
9589
// Fetch current feeds
9690
(uint256[] memory feedValues, int8[] memory decimals, ) = ftsoV2
9791
.getFeedsById(_baseAndQuoteFeedIds);

examples/developer-hub-solidity/FtsoV2FeedConsumer.sol

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,23 @@ import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/costo
1111
*/
1212
contract FtsoV2FeedConsumer {
1313
TestFtsoV2Interface internal ftsoV2;
14-
1514
// Feed IDs, see https://dev.flare.network/ftso/feeds for full list
1615
bytes21[] public feedIds = [
17-
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
18-
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
19-
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
16+
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
17+
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
18+
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
2019
];
2120

2221
/**
2322
* Get the current value of the feeds.
2423
*/
2524
function getFtsoV2CurrentFeedValues()
26-
external
27-
returns (
28-
uint256[] memory _feedValues,
29-
int8[] memory _decimals,
30-
uint64 _timestamp
31-
)
25+
external
26+
returns (
27+
uint256[] memory _feedValues,
28+
int8[] memory _decimals,
29+
uint64 _timestamp
30+
)
3231
{
3332
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
3433
ftsoV2 = ContractRegistry.getTestFtsoV2();

0 commit comments

Comments
 (0)