Professional Documents
Culture Documents
FTSO Price Provider: TL DR
FTSO Price Provider: TL DR
Providing prices to the Flare time series oracle for fun and for profit
TL;DR
On chain FTSO prices will be updated every few minutes. Any user (address) can provide
prices (data) by reading prices from any chosen source and submitting them to a dedicated
API on the ftso contract. Any FLR holder can participate by delegating their vote power (1:1
based on flare balance) to another address (price provider) that submits prices. Good price
feeds will be rewarded with part of the FLR inflation, in the form of FLR tokens on the Flare
network. An address must have some minimum vote power in order to submit prices.
FTSO overview
The FTSO or ‘Flare Time Series Oracle’ is a service to gather price (and data) signals of
off-chain assets for consumption by other smart contracts on the Flare blockchain. The
system is designed to encourage FLR holders to submit accurate prices to the FTSO
contracts. Prices will be submitted in price epochs of a few minutes. For every price epoch, a
weighted median algorithm will aggregate all price submissions to find the median price,
which will become the current FTSO price. Good price submissions will be rewarded with
newly minted FLR tokens (FLR inflation).
Price submissions are considered good if they are within the interquartile range (within 25%
of either side) of the submissions around the weighted median price. The rewards will be
distributed between good submissions according to the relative weight (balance / vote
power) of each address.
An FTSO contract will be deployed for any new data signal supported by the Flare network,
as determined by governance. The Flare Foundation currently plans to deploy contracts that
will provide USD prices of FLR, XRP, LTC, XLM, DOGE, ADA, Algo, BCH, Digi and more to
come.
More detail about the FTSO can be found here: https://blog.flare.xyz/ftso-a-breakdown/
WFLR must be used in the price submission process. It is an ERC20 token that also
supports vote power delegation from one address to another. Meaning, any WFLR holder
can delegate their vote power to any other addresses. FLR depositors always maintain
custody of their WFLR. When delegating vote power, WFLR holders retain full custody
over their WFLR.
Note that although WFLR and FLR always have the same value, they differ in usage. Only
FLR can be used to pay for flare network transactions (gas), while only WFLR can be used
to represent and delegate vote power in price submissions.
Example:
Alice has 10 FLR, she has no vote power delegated to her.
Alice wraps her 10 FLR by calling WFLR.deposit(), thus she now has vote power of 10.
Bob has 30 WFLR so he has vote power of 30.
Bob decides to delegate 50% of his vote power to Alice. Now Alice has vote power of 25 and
Bob has vote power of 15.
Bob receives 20 more WFLRtokens, so now Alice has vote power of 35 and Bob has vote
power of 25.
Notice how when a delegator receives additional WFLR, the contract automatically updates
vote power for all relevant delegatees according to their delegation percentage. It is
important to note that although Bob has delegated 50% of his vote power to Alice, he still
retains his 30 WFLR.
Note that for the Beta run of FTSOs, any address holding WFLR can submit prices However,
there will be minimum thresholds of vote power required to submit prices at mainnet launch.
Reveal price
function revealPrice(uint256 _epochId, uint256 _price, uint256
_random) external;
Epoch ID should match the epoch in which the hash was submitted. For keeping track of
epoch IDs, see the next section.
Price and random should be the same ones that were used to create the hash in the relevant
price epoch period. If they don’t match, the transaction will be reverted and the committed
price will not be included in the price determination algorithm.
As soon as the reveal period ends, the weighted median algorithm will process all revealed
prices, and publish the median as the current price of the asset.
function revealPrices(
uint256 _epochId,
IIFtso[] memory _ftsos,
uint256[] memory _prices,
uint256[] memory _randoms
) external;
With batched transactions the price provider sends a list of FTSO addresses and the
relevant data according to the operation type (submit or reveal). One can use this contract to
interact with all FTSOs or a parietal list.
uint256 _epochId,
uint256 _epochSubmitEndTime,
uint256 _epochRevealEndTime,
uint256 _votePowerBlock,
uint256 _minVotePowerFlr,
uint256 _minVotePowerAsset,
bool _fallbackMode
);
● All time values are using timestamp from the unix epoch.
● When in fallback mode, the FTSO takes price values from a trusted list of addresses
(chain link style).
Events
Price submission event
event PriceHashSubmitted(
address indexed submitter, uint256 indexed epochId, bytes32
hash, uint256 timestamp
);
A submitter can listen for this event to know which epoch ID the price was submitted for.
event PriceEpochInitializedOnFtso(
uint256 indexed epochId, uint256 endTime, uint256 timestamp
);
let providerVotePower;
let validFtsoAddressList[];
let ftsoPriceHashes[];
let ftsoPrices[];
let ftsoRandoms[];
{
epochId;
epochSubmitEndTime;
epochRevealEndTime;
votePowerBlock;
lowFlrVotePowerThreshold;
isFallBackMode;
} = ftso.getPriceEpochData();
validFtsoAddressList.push(FTSOAddressList[i]);
function percentToBips(percent) {
return percent * 100;
}
function wait(waitUntil) {
while(now() < waitUntil) {
// sleep 1 second
sleep(1);
}
}