You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FTSO Adapters, provided by the `@flarenetwork/ftso-adapters` library, allow decentralized applications (dApps) built for other popular oracle interfaces to integrate with Flare's FTSO with minimal code changes. The library provides adapters for Pyth, Chainlink, API3, Band Protocol, and Chronicle. These adapters act as a compatibility layer, translating the FTSO's data structure into the format expected by each respective oracle's interface.
30
+
FTSO Adapters, provided by the `@flarenetwork/ftso-adapters` library, allow decentralized applications (dApps) built for other popular oracle interfaces to integrate with Flare's FTSO with minimal code changes.
31
+
The library provides adapters for Pyth, Chainlink, API3, Band Protocol, and Chronicle.
32
+
These adapters act as a compatibility layer, translating the FTSO's data structure into the format expected by each respective oracle's interface.
31
33
32
-
This enables a seamless migration path for projects looking to leverage the speed, decentralization, and cost-effectiveness of Flare's native oracle. This guide focuses on the specific code modifications required to migrate your existing dApp.
34
+
This enables a seamless migration path for projects looking to leverage the speed, decentralization, and cost-effectiveness of Flare's native oracle.
35
+
This guide focuses on the specific code modifications required to migrate your existing dApp.
33
36
34
37
All code examples can be found in our [hardhat-starter-kit](https://github.com/flare-network/hardhat-starter-kit/tree/main/contracts/adapters).
35
38
36
39
## Migrating Your dApp: Key Code Changes
37
40
38
-
Migrating from an external oracle to Flare's FTSO adapter involves a paradigm shift: instead of your contract calling an external oracle for data, your contract becomes its own oracle by integrating an adapter library. This process involves two key areas of change: on-chain contract modifications and a new off-chain keeper process.
41
+
Migrating to a Flare FTSO adapter requires a different approach to handling oracle data. Instead of your contract calling an external oracle, it will now manage price data internally by using an adapter library.
42
+
This process involves two main changes: modifying your smart contract and setting up a new off-chain keeper process.
39
43
40
44
### 1. On-Chain: Integrate the Adapter Library
41
45
42
-
The core of the migration happens within your smart contract. You will modify it to store, update, and serve the FTSO price data itself.
46
+
The main changes happen within your smart contract. You will modify it to store, update, and serve the FTSO price data itself.
43
47
44
-
-**State Variables**: Instead of storing an address to an external oracle proxy, you add state variables to your contract to manage the FTSO feed and cache the price data.
48
+
-**State Variables**: Instead of storing an address to an external oracle, you add state variables to your contract to manage the FTSO feed and cache the price data.
-**After**: `bytes21 public immutable ftsoFeedId; FtsoChainlinkAdapterLibrary.Round private _latestPriceData;`
47
51
48
-
-**Constructor**: Your constructor no longer needs a proxy address. Instead, it takes FTSO-specific configuration, such as the `ftsoFeedId` and any adapter-specific parameters (like `chainlinkDecimals`).
52
+
-**Constructor**: Your constructor no longer needs an oracle's address. Instead, it takes FTSO-specific information, such as the `ftsoFeedId` and any other parameters the adapter needs (like `chainlinkDecimals`).
-**Implement `refresh()`**: You must add a public `refresh()` function. This function's only job is to call the adapter library's `refresh` logic, passing in your contract's state variables to be updated with the latest FTSO price.
56
+
-**Implement `refresh()`**: You must add a public `refresh()` function. This function's only job is to call the adapter library's `refresh` logic, which updates your contract's state variables with the latest FTSO price.
53
57
54
-
-**Implement the Oracle Interface**: You then implement the standard `view` function for the oracle you are migrating from (e.g., `latestRoundData()` for Chainlink, `getPriceNoOlderThan()` for Pyth). This function calls the corresponding logic from the adapter library, reading directly from your contract's cached state.
58
+
-**Implement the Oracle Interface**: You then add the standard `view` function for the oracle you are migrating from (e.g., `latestRoundData()` for Chainlink).
59
+
This function calls the corresponding logic from the adapter library, reading directly from your contract's cached state.
55
60
56
-
-**No Change to Core Logic**: Crucially, your dApp's internal business logic, which consumes the price data, remains unchanged. It continues to call the same standard oracle functions as before (e.g., `latestRoundData()`), but now it's calling a function implemented directly on your own contract.
61
+
-**No Change to Core Logic**: Your dApp's internal logic that uses the price data remains unchanged.
62
+
It continues to call the same standard oracle functions as before (e.g., `latestRoundData()`), but now it's calling a function implemented directly within your own contract.
57
63
58
64
### 2. Off-Chain: Set Up a Keeper Bot
59
65
60
-
Since your contract now controls its own price updates, you need an external process to trigger them.
66
+
Since your contract now manages its own price updates, you need an external process to trigger them.
61
67
62
68
-**Create a Keeper Script**: This is a simple script that connects to the network and periodically calls the public `refresh()` function on your deployed contract.
63
-
-**Run the Keeper**: This script ensures the cached price in your contract remains fresh and doesn't become stale. It replaces the need to rely on the oracle provider's keeper network, giving you direct control over the frequency—and therefore the cost—of your price updates.
69
+
-**Run the Keeper**: This script ensures the price cached in your contract stays fresh. It replaces the need to rely on the oracle provider's keepers, giving you direct control over how often your prices are updated and how much you spend on gas.
0 commit comments