Skip to content
113 changes: 3 additions & 110 deletions docs/ftso/solidity-reference/FtsoV2Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ description: Primary interface for interacting with FTSOv2.
import Remix from "@site/src/components/remix";
import CodeBlock from "@theme/CodeBlock";
import FTSOV2FeedById from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedById.sol";
import FTSOV2FeedByIdWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIdWei.sol";
import FTSOV2FeedByIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIndex.sol";
import FTSOV2FeedByIndexWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIndexWei.sol";
import FTSOV2FeedByIdIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIdIndex.sol";
import FTSOV2FeedByIdWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedByIdWei.sol";
import FTSOV2FeedsById from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsById.sol";
import FTSOV2FeedsByIdWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIdWei.sol";
import FTSOV2FeedsByIndex from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIndex.sol";
import FTSOV2FeedsByIndexWei from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2FeedsByIndexWei.sol";
import FTSOV2VerifyProof from "!!raw-loader!/examples/developer-hub-solidity/FTSOV2VerifyProof.sol";

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

### getFeedByIndexInWei

Returns value in wei and timestamp of a feed.
A fee (calculated by the FeeCalculator contract) may need to be paid.

```solidity
function getFeedByIndexInWei(
uint256 _index
) external payable returns (
uint256 _value,
uint64 _timestamp
);
```

#### Parameters

- `_index`: The index of the feed, corresponding to feed id in the FastUpdatesConfiguration contract.

#### Returns

- `_value`: The value for the requested feed in wei (i.e. with 18 decimal places).
- `_timestamp`: The timestamp of the last update.

<details>
<summary>Sample contract usage</summary>

<CodeBlock language="solidity" title="FTSOV2FeedByIndexWei.sol">
{FTSOV2FeedByIndexWei}
</CodeBlock>

</details>

<Remix fileName="FTSOV2FeedByIndexWei.sol">Open sample in Remix</Remix>
<br></br>

### getFeedId

Returns the feed id at a given index. Removed (unused) feed index will return bytes21(0).

```solidity
function getFeedId(
uint256 _index
) external view returns (
bytes21 _feedId
);
```

#### Parameters

- `_index`: The index.

#### Returns

- `_feedId`: The feed id.

<details>
<summary>Sample contract usage</summary>

<CodeBlock language="solidity" title="FTSOV2FeedByIdIndex.sol">
{FTSOV2FeedByIdIndex}
</CodeBlock>

</details>

<Remix fileName="FTSOV2FeedByIdIndex.sol">Open sample in Remix</Remix>
<br></br>

### getFeedIndex

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

### getFeedsByIndex

Returns stored data of each feed.
A fee (calculated by the FeeCalculator contract) may need to be paid.

```solidity
function getFeedsByIndex(
uint256[] _indices
) external payable returns (
uint256[] _values,
int8[] _decimals,
uint64 _timestamp
);
```

#### Parameters

- `_indices`: Indices of the feeds, corresponding to feed ids in the FastUpdatesConfiguration contract.

#### Returns

- `_values`: The list of values for the requested feeds.
- `_decimals`: The list of decimal places for the requested feeds.
- `_timestamp`: The timestamp of the last update.

<details>
<summary>Sample contract usage</summary>

<CodeBlock language="solidity" title="FTSOV2FeedsByIndex.sol">
{FTSOV2FeedsByIndex}
</CodeBlock>

</details>

<Remix fileName="FTSOV2FeedsByIndex.sol">Open sample in Remix</Remix>
<br></br>

### getFeedsByIndexInWei

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

```solidity
struct FeedDataWithProof {
bytes32[] proof;
struct FtsoV2Interface.FeedData body;
bytes32[] proof;
struct FtsoV2Interface.FeedData body;
}
```
26 changes: 8 additions & 18 deletions examples/developer-hub-solidity/FTSOV2FeedById.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@ import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/costo
contract FtsoV2FeedConsumerById {
TestFtsoV2Interface internal ftsoV2;
// Example Feed ID for FLR/USD
bytes21 public feedId = bytes21(0x01464c522f55534400000000000000000000000000); // FLR/USD

/**
* Constructor initializes the FTSOv2 contract.
* The contract registry is used to fetch the FtsoV2 contract address.
*/
constructor() {
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();
}
bytes21 public feedId =
bytes21(0x01464c522f55534400000000000000000000000000); // FLR/USD

/**
* Get the current value of a specific feed by its ID.
Expand All @@ -30,15 +22,13 @@ contract FtsoV2FeedConsumerById {
* @return _timestamp The timestamp of the last feed update.
*/
function getFtsoV2FeedValueById()
external
payable
returns (
uint256 _feedValue,
int8 _decimals,
uint64 _timestamp
)
external
payable
returns (uint256 _feedValue, int8 _decimals, uint64 _timestamp)
{
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();
/* Retrieves the latest value, decimals, and timestamp for the specified feed ID. */
return ftsoV2.getFeedById(feedId);
}
}
}
50 changes: 10 additions & 40 deletions examples/developer-hub-solidity/FTSOV2FeedByIdWei.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,28 @@ import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/costo
*/
contract FtsoV2FeedTracker {
TestFtsoV2Interface internal ftsoV2;

// Feed data structure to store multiple feed values with timestamps
struct FeedInfo {
uint256 valueInWei;
uint64 timestamp;
}

// Mapping to store the latest feed data for a given index
mapping(uint256 => FeedInfo) public feedDataByIndex;
uint256 public highestValueIndex;
uint256 public highestValueInWei;
bytes21 public feedId = bytes21(0x01464c522f55534400000000000000000000000000); // FLR/USD

// Event to track feed retrieval
event FeedFetched(uint256 index, uint256 valueInWei, uint64 timestamp);

/**
* Constructor initializes the FTSOv2 contract.
* The contract registry is used to fetch the FtsoV2 contract address.
*/
constructor() {
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();
}
event FeedFetched(bytes21 feedId, uint256 valueInWei, uint64 timestamp);

/**
* Get the current value of a specific feed by its index, in wei.
* @param _index The index of the feed to retrieve.
* @return _feedValue The latest price value of the feed in wei.
* @return _timestamp The timestamp of the last update for the feed.
*/
function getFeedValueByIndexInWei(uint256 _index)
external
payable
returns (uint256 _feedValue, uint64 _timestamp)
function getFeedValueByIdWei()
external
payable
returns (uint256 _feedValue, uint64 _timestamp)
{
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();
// Retrieve feed value and timestamp from the FtsoV2 contract
(_feedValue, _timestamp) = ftsoV2.getFeedByInWei{value: msg.value}(_index);

// Store the feed value and timestamp in the contract's storage
feedDataByIndex[_index] = FeedInfo({
valueInWei: _feedValue,
timestamp: _timestamp
});

// Update the highest value feed if applicable
if (_feedValue > highestValueInWei) {
highestValueInWei = _feedValue;
highestValueIndex = _index;
}
(_feedValue, _timestamp) = ftsoV2.getFeedByIdInWei(feedId);

// Emit an event to log the feed retrieval
emit FeedFetched(_index, _feedValue, _timestamp);
emit FeedFetched(feedId, _feedValue, _timestamp);
}

}
24 changes: 7 additions & 17 deletions examples/developer-hub-solidity/FTSOV2FeedByIndex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,21 @@ contract FtsoV2FeedConsumerByIndex {
// Example index for a feed (corresponding to a feed id)
uint256 public feedIndex = 1; // Example: FLR/USD

/**
* Constructor initializes the FTSOv2 contract.
* The contract registry is used to fetch the FtsoV2 contract address.
*/
constructor() {
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();
}

/**
* Get the current value of a specific feed by its index.
* @return _feedValue The latest price value of the feed.
* @return _decimals The decimal precision of the feed value.
* @return _timestamp The timestamp of the last feed update.
*/
function getFtsoV2FeedValueByIndex()
external
payable
returns (
uint256 _feedValue,
int8 _decimals,
uint64 _timestamp
)
external
payable
returns (uint256 _feedValue, int8 _decimals, uint64 _timestamp)
{
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();

/* Retrieves the latest value, decimals, and timestamp for the specified feed index. */
return ftsoV2.getFeedByIndex(feedIndex);
}
}
}
32 changes: 12 additions & 20 deletions examples/developer-hub-solidity/FTSOV2FeedsById.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,25 @@ contract FtsoV2FeedConsumer {
TestFtsoV2Interface internal ftsoV2;
// Feed IDs, see https://dev.flare.network/ftso/feeds for full list
bytes21[] public feedIds = [
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
];

/**
* Constructor initializes the FTSOv2 contract.
* The contract registry is used to fetch the FtsoV2 contract address.
*/
constructor() {
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();
}

/**
* Get the current value of the feeds.
*/
function getFtsoV2CurrentFeedValues()
external
view
returns (
uint256[] memory _feedValues,
int8[] memory _decimals,
uint64 _timestamp
)
external
returns (
uint256[] memory _feedValues,
int8[] memory _decimals,
uint64 _timestamp
)
{
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();
/* Your custom feed consumption logic. In this example the values are just returned. */
return ftsoV2.getFeedsById(feedIds);
}
}
}
34 changes: 15 additions & 19 deletions examples/developer-hub-solidity/FTSOV2FeedsByIdWei.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ contract FtsoV2FeedConsumer {

// Feed IDs, see https://dev.flare.network/ftso/feeds for full list
bytes21[] public feedIds = [
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD
bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
];

// Event to log feed values retrieval
event FeedValuesRetrieved(bytes21[] indexed feedIds, uint256[] values, uint64 timestamp);

/**
* Constructor initializes the FTSOv2 contract.
* The contract registry is used to fetch the FtsoV2 contract address.
*/
constructor() {
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();
}
event FeedValuesRetrieved(
bytes21[] indexed feedIds,
uint256[] values,
uint64 timestamp
);

/**
* Get the current value of the feeds in wei.
Expand All @@ -38,18 +33,19 @@ contract FtsoV2FeedConsumer {
* @return _values The list of values for the requested feeds in wei.
* @return _timestamp The timestamp of the last update.
*/
function getFeedsByIdInWei(bytes21[] calldata _feedIds)
external
payable
returns (uint256[] memory _values, uint64 _timestamp)
{
function getFeedsByIdInWei(
bytes21[] calldata _feedIds
) external payable returns (uint256[] memory _values, uint64 _timestamp) {
// Ensure that the length of the feed IDs is non-zero
require(_feedIds.length > 0, "No feed IDs provided");

/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
ftsoV2 = ContractRegistry.getTestFtsoV2();

// Retrieve the feed values and timestamp from the FTSOv2 contract
(_values, _timestamp) = ftsoV2.getFeedsByIdInWei(_feedIds);

// Emit an event to log the retrieved feed values
emit FeedValuesRetrieved(_feedIds, _values, _timestamp);
}
}
}
Loading
Loading