Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FTSOv2 guides #51

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/ftso/1-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ You can use FTSOv2 to connect your smart contracts with real-world data feeds. F
If you are new to smart contract development, learn how to [deploy your first smart contract](/guides/deploy-first-contract) before you start this guide.
:::

:::info
If you are familiar with Hardhat or Foundry, use the [Hardhat and Foundry Starter Kit](/guides/hardhat-foundry-starter-kit) to get started with Flare development.
:::

## Sample contract

This example smart contract queries the latest feed values for FLR/USD, BTC/USD, and ETH/USD from FTSOv2 on Flare Testnet Coston2.
Expand Down
48 changes: 37 additions & 11 deletions docs/ftso/guides/change-quote-feed.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Change quote feed
tags: [quickstart, ftso, solidity]
tags: [intermediate, ftso, solidity]
slug: change-quote-feed
description: Change block-latency quote feeds using Solidity.
keywords:
Expand All @@ -13,16 +13,23 @@ keywords:
solidity,
remix,
]
sidebar_position: 2
sidebar_position: 3
---

import Remix from "@site/src/components/remix";
import SetEvmVersionRemix from "/static/img/set-evm-version-remix.png";

This guide will show you how to fetch the latest feed values for two feeds and convert them to a new quote feed. For example, if you need the price of `BTC/ETH`, you can fetch the latest feed values for `BTC/USD` and `ETH/USD` and calculate the price of `BTC/ETH = (BTC/USD) / (ETH/USD)`.

```solidity title="FtsoV2ChangeQuoteFeed.sol"// SPDX-License-Identifier: MIT
In the following smart contract, for `BTC/USD` (feed index `2`) and `ETH/USD` (feed index `9`), returning the value of `BTC/ETH`, the function signature would be:

```solidity
getNewQuoteFeedValue([2, 9])
```

```solidity title="FtsoV2ChangeQuoteFeed.sol"
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity <0.9.0;

import { IFastUpdater } from "@flarenetwork/flare-periphery-contracts/flare/ftso/userInterfaces/IFastUpdater.sol";

Expand Down Expand Up @@ -104,16 +111,35 @@ contract FtsoV2ChangeQuoteFeed {
{/* prettier-ignore */}
<Remix href="https://remix.ethereum.org/#version=soljson-v0.8.19+commit.7dd6d404.js&optimize=true&runs=200&gist=d6181b71e7932701efbc6c3c78898f5a">Open in Remix</Remix>

<br />
<br></br>

For the example of `BTC/USD` (feed index `2`) and `ETH/USD` (feed index `9`), returning the value of `BTC/ETH`, the function signature would be:
:::warning

```solidity
getNewQuoteFeedValue([2, 9])
```
When compiling and deploying the contract:

- **Using Remix:** Set EVM version to `london` in the **Advanced Configurations** section of the **Solidity Compiler** tab:

{" "}
<img src={SetEvmVersionRemix} style={{ width: 300 }} />

- **Using Standard Solidity JSON:** Set `evmVersion` to `london`:

```json
{
"settings": {
"optimizer": {
/* ... */
},
"evmVersion": "london"
}
}
```

- **Using `solc` CLI:** Set `--evm-version` to `london`:

:::tip
You can do this with any two feeds you want to convert to a new quote feed. See a full list of feed indexes on the [Block-Latency Feeds](../feeds) page.
```bash
solc --evm-version london <args>
```

:::

Expand Down
30 changes: 18 additions & 12 deletions docs/ftso/guides/make-volatility-incentive.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Make a volatility incentive
tags: [quickstart, ftso, javascript, python]
tags: [intermediate, ftso, javascript, python]
slug: make-volatility-incentive
description: Make a volatility incentive offer using JS or Python.
keywords:
Expand All @@ -14,7 +14,7 @@ keywords:
javascript,
python,
]
sidebar_position: 3
sidebar_position: 5
---

import TabItem from "@theme/TabItem";
Expand All @@ -26,21 +26,27 @@ Before reading this guide, make sure you understand the [FTSOv2 Architecture](/f

This guide provides code examples demonstrating how to make an FTSOv2 volatility incentive offer using various programming languages. To make a volatility incentive offer, you need three key pieces of information:

**1. RPC Endpoint URL:** The RPC Endpoint URL determines which network your code will interact with. You can use a node provider service or point to your own client. A comprehensive list of public and private RPC endpoints for all Flare networks is available on the [Network Configuration](../../network#configuration) page.
1. **RPC Endpoint URL:** The RPC Endpoint URL determines which network your code will interact with. You can use a node provider service or point to your own client. A comprehensive list of public and private RPC endpoints for all Flare networks is available on the [Network Configuration](../../network#configuration) page.

**2. Contract Address:** The address for the `FastUpdateIncentiveManager` contract varies by network. You can obtain this address in two ways:
2. **Contract Address:** The address for the `FastUpdateIncentiveManager` contract varies by network. You can obtain this address in two ways:

- **From the Solidity Reference page:** Find the `FastUpdateIncentiveManager` address for each network on the [Solidity Reference](../solidity-reference) page.
- **From the Solidity Reference page:** Find the `FastUpdateIncentiveManager` address for each network on the [Solidity Reference](../solidity-reference) page.

**OR**
**OR**

- **Query the FlareContractRegistry Contract:** The `FlareContractRegistry` contract has the same address across all networks. You can query it to get the `FastUpdateIncentiveManager` contract address. Refer to the specific language guides for examples:
- [JavaScript](/guides/flare-for-javascript-developers#make-query)
- [Python](/guides/flare-for-python-developers#make-query)
- [Rust](/guides/flare-for-rust-developers#make-query)
- [Go](/guides/flare-for-go-developers#make-query)
- **Query the FlareContractRegistry Contract:** The `FlareContractRegistry` contract has the same address across all networks. You can query it to get the `FastUpdateIncentiveManager` contract address. Refer to the specific language guides for examples:
- [JavaScript](/guides/flare-for-javascript-developers#make-query)
- [Python](/guides/flare-for-python-developers#make-query)
- [Rust](/guides/flare-for-rust-developers#make-query)
- [Go](/guides/flare-for-go-developers#make-query)

**3. Cost of Increasing the Sample Size:** FTSOv2 allows you to dynamically increase the sample size, i.e., the expected number of providers who can submit a block-latency feed update. The cost for this increases dynamically with the expected sample size. A single volatility incentive lasts for a period of 8 blocks.
3. **Cost of Increasing the Sample Size:** FTSOv2 allows you to dynamically increase the sample size, i.e., the expected number of providers who can submit a block-latency feed update. The cost for this increases dynamically with the expected sample size. A single volatility incentive lasts for a period of 8 blocks.

:::tip

All code examples in this guide are also available in the [developer-hub repository](https://github.com/flare-foundation/developer-hub/tree/main/code_examples).

:::

<Tabs block>
<TabItem value="JavaScript" label="JavaScript" default>
Expand Down
20 changes: 10 additions & 10 deletions docs/ftso/guides/query-feed-configuration.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Query feed configuration
tags: [quickstart, ftso, python, rust, javascript, go]
tags: [intermediate, ftso, python, rust, javascript, go]
slug: query-feed-configuration
description: Query feed configuration using JS, Python, Rust, or Go.
keywords:
Expand All @@ -22,19 +22,19 @@ import Tabs from "@theme/Tabs";

This guide provides code examples demonstrating how to read FTSOv2 feed configurations off-chain using various programming languages. To achieve this, you need two key pieces of information:

**1. RPC Endpoint URL:** The RPC Endpoint URL determines which network your code will interact with. You can either use a node provider service or point to your own client. A list of public and private RPC endpoints for all Flare networks is available on the [Network Configuration](../../network#configuration) page.
1. **RPC Endpoint URL:** The RPC Endpoint URL determines which network your code will interact with. You can either use a node provider service or point to your own client. A list of public and private RPC endpoints for all Flare networks is available on the [Network Configuration](../../network#configuration) page.

**2. Contract Address:** The address for the `FastUpdatesConfiguration` contract varies by network. You can obtain this address in two ways:
2. **Contract Address:** The address for the `FastUpdatesConfiguration` contract varies by network. You can obtain this address in two ways:

- **From the Solidity Reference page:** Find the `FastUpdatesConfiguration` address for each network on the [Solidity Reference](../solidity-reference) page.
- **From the Solidity Reference page:** Find the `FastUpdatesConfiguration` address for each network on the [Solidity Reference](../solidity-reference) page.

**OR**
**OR**

- **Query the FlareContractRegistry Contract:** The `FlareContractRegistry` contract has the same address across all networks. You can query it to get the `FastUpdatesConfiguration` contract address. Refer to the specific language guides for examples:
- [JavaScript](/guides/flare-for-javascript-developers#make-query)
- [Python](/guides/flare-for-python-developers#make-query)
- [Rust](/guides/flare-for-rust-developers#make-query)
- [Go](/guides/flare-for-go-developers#make-query)
- **Query the FlareContractRegistry Contract:** The `FlareContractRegistry` contract has the same address across all networks. You can query it to get the `FastUpdatesConfiguration` contract address. Refer to the specific language guides for examples:
- [JavaScript](/guides/flare-for-javascript-developers#make-query)
- [Python](/guides/flare-for-python-developers#make-query)
- [Rust](/guides/flare-for-rust-developers#make-query)
- [Go](/guides/flare-for-go-developers#make-query)

:::tip

Expand Down
24 changes: 12 additions & 12 deletions docs/ftso/guides/read-feeds-offchain.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Read feeds offchain
tags: [quickstart, ftso, python, rust, javascript, go]
tags: [intermediate, ftso, python, rust, javascript, go]
slug: read-feeds-offchain
description: Read block-latency feeds using JS, Python, Rust, or Go.
keywords:
Expand All @@ -14,29 +14,29 @@ keywords:
flare-time-series-oracle,
flare-network,
]
sidebar_position: 1
sidebar_position: 2
---

import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";

This guide provides code examples demonstrating how to read FTSOv2 feeds off-chain using various programming languages. To read a block-latency feed off-chain, you need three key pieces of information:

**1. RPC Endpoint URL:** The RPC Endpoint URL determines which network your code will interact with. You can use a node provider service or point to your own client. A comprehensive list of public and private RPC endpoints for all Flare networks is available on the [Network Configuration](../../network#configuration) page.
1. **RPC Endpoint URL:** The RPC Endpoint URL determines which network your code will interact with. You can use a node provider service or point to your own client. A comprehensive list of public and private RPC endpoints for all Flare networks is available on the [Network Configuration](../../network#configuration) page.

**2. Contract Address:** The address for the `FastUpdater` contract varies by network. You can obtain this address in two ways:
2. **Contract Address:** The address for the `FastUpdater` contract varies by network. You can obtain this address in two ways:

- **From the Solidity Reference page:** Find the `FastUpdater` address for each network on the [Solidity Reference](../solidity-reference) page.
- **From the Solidity Reference page:** Find the `FastUpdater` address for each network on the [Solidity Reference](../solidity-reference) page.

**OR**
**OR**

- **Query the FlareContractRegistry Contract:** The `FlareContractRegistry` contract has the same address across all networks. You can query it to get the `FastUpdater` contract address. Refer to the specific language guides for examples:
- [JavaScript](/guides/flare-for-javascript-developers#make-query)
- [Python](/guides/flare-for-python-developers#make-query)
- [Rust](/guides/flare-for-rust-developers#make-query)
- [Go](/guides/flare-for-go-developers#make-query)
- **Query the FlareContractRegistry Contract:** The `FlareContractRegistry` contract has the same address across all networks. You can query it to get the `FastUpdater` contract address. Refer to the specific language guides for examples:
- [JavaScript](/guides/flare-for-javascript-developers#make-query)
- [Python](/guides/flare-for-python-developers#make-query)
- [Rust](/guides/flare-for-rust-developers#make-query)
- [Go](/guides/flare-for-go-developers#make-query)

**3. Feed Indexes:** The feeds you want to read are uniquely identified by their index. A list of feed indexes is provided on the [Block-Latency Feeds](../feeds) page.
3. **Feed Indexes:** The feeds you want to read are uniquely identified by their index. A list of feed indexes is provided on the [Block-Latency Feeds](../feeds) page.

:::tip

Expand Down
154 changes: 154 additions & 0 deletions docs/ftso/guides/read-feeds-onchain.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
---
title: Read feeds onchain
tags: [intermediate, ftso, solidity]
slug: read-feeds-onchain
description: Read block-latency feeds using Solidity.
keywords: [solidity, ftso, oracle, flare-time-series-oracle, flare-network]
sidebar_position: 1
---

import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";
import SetEvmVersionRemix from "/static/img/set-evm-version-remix.png";

This guide provides code examples demonstrating how to read FTSOv2 feeds off-chain. To read a block-latency feed on-chain, you need two key pieces of information:

1. **Contract Address:** The address for the `FastUpdater` contract varies by network. You can obtain this address by querying the `FlareContractRegistry` contract, which has the same address across all networks.

FlareContractRegistry: `0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019`

2. **Feed Indexes:** The feeds you want to read are uniquely identified by their index. A list of feed indexes is provided on the [Block-Latency Feeds](../feeds) page.

:::info
If you are familiar with Hardhat or Foundry, use the [Hardhat and Foundry Starter Kit](/guides/hardhat-foundry-starter-kit) to get started with Flare development.
:::

<Tabs block>
<TabItem value="flare" label="Flare Mainnet">
```solidity title="FtsoV2FeedConsumer.sol"
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { IFlareContractRegistry } from "@flarenetwork/flare-periphery-contracts/flare/util-contracts/userInterfaces/IFlareContractRegistry.sol";
import { IFastUpdater } from "@flarenetwork/flare-periphery-contracts/flare/ftso/userInterfaces/IFastUpdater.sol";

/**
* THIS IS AN EXAMPLE CONTRACT USING HARDCODED VALUES.
* DO NOT USE THIS CODE IN PRODUCTION.
*/

contract FtsoV2FeedConsumer {
IFastUpdater internal ftsoV2;
// Feed indexes: 0 = FLR/USD, 2 = BTC/USD, 9 = ETH/USD
uint256[] public feedIndexes = [0, 2, 9];

constructor() {
contractRegistry = IFlareContractRegistry(0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019);
ftsoV2 = IFastUpdater(contractRegistry.getContractAddressByName("FastUpdater"));
}

/**
* Get the current value of the feeds.
*/
function getFtsoV2CurrentFeedValues()
external
view
returns (
uint256[] memory _feedValues,
int8[] memory _decimals,
int64 _timestamp
)
{
(
uint256[] memory feedValues,
int8[] memory decimals,
int64 timestamp
) = ftsoV2.fetchCurrentFeeds(feedIndexes);
/* Your custom feed consumption logic. */
/* In this example the feed values, decimals and last updated timestamp are just returned. */
return (feedValues, decimals, timestamp);
}
}
```
</TabItem>
<TabItem value="coston2" label="Flare Testnet Coston2">
```solidity title="FtsoV2FeedConsumer.sol"
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { IFlareContractRegistry } from "@flarenetwork/flare-periphery-contracts/coston2/util-contracts/userInterfaces/IFlareContractRegistry.sol";
import { IFastUpdater } from "@flarenetwork/flare-periphery-contracts/coston2/ftso/userInterfaces/IFastUpdater.sol";

/**
* THIS IS AN EXAMPLE CONTRACT USING HARDCODED VALUES.
* DO NOT USE THIS CODE IN PRODUCTION.
*/

contract FtsoV2FeedConsumer {
IFastUpdater internal ftsoV2;
// Feed indexes: 0 = FLR/USD, 2 = BTC/USD, 9 = ETH/USD
uint256[] public feedIndexes = [0, 2, 9];

constructor() {
contractRegistry = IFlareContractRegistry(0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019);
ftsoV2 = IFastUpdater(contractRegistry.getContractAddressByName("FastUpdater"));
}

/**
* Get the current value of the feeds.
*/
function getFtsoV2CurrentFeedValues()
external
view
returns (
uint256[] memory _feedValues,
int8[] memory _decimals,
int64 _timestamp
)
{
(
uint256[] memory feedValues,
int8[] memory decimals,
int64 timestamp
) = ftsoV2.fetchCurrentFeeds(feedIndexes);
/* Your custom feed consumption logic. */
/* In this example the feed values, decimals and last updated timestamp are just returned. */
return (feedValues, decimals, timestamp);
}
}
```
</TabItem>

</Tabs>

<br></br>

:::warning

When compiling and deploying the contract:

- **Using Remix:** Set EVM version to `london` in the **Advanced Configurations** section of the **Solidity Compiler** tab:

{" "}
<img src={SetEvmVersionRemix} style={{ width: 300 }} />

- **Using Standard Solidity JSON:** Set `evmVersion` to `london`:

```json
{
"settings": {
"optimizer": {
/* ... */
},
"evmVersion": "london"
}
}
```

- **Using `solc` CLI:** Set `--evm-version` to `london`:

```bash
solc --evm-version london <args>
```

:::
Binary file added static/img/set-evm-version-remix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading