Integration Details

Triple's on-chain data feeds can be accessed in two distinct ways:

  1. Direct Access: This method involves reading the data directly from the Triple Feeds smart contract, offering lower gas requirements.

  2. Via Reader: For projects that require integration but are unable to modify their existing smart contracts, data can be retrieved from the Triple Feeds Reader smart contracts. The Triple Feeds Reader is linked to the Triple Feeds smart contract, albeit with one additional step, resulting in higher gas costs compared to Direct Access.

Smart Contract hierarchy

Getting the address of the latest Triple Feeds smart contract

Address of the lastest Triple Feeds smart contract can be resolved by using the Triple smart contract.

📘

Addresses of the Triple Registry contracts for the different blockchains can be found in here.

Address can be resolved with the following method:

IRegistry.getAddress(bytes32("TripleFeeds"))

Direct access

It is recommended option as it is the most gas effective.

The TripleFeeds smart contract is where all prices are submitted by the on-chain data feature of the Triple Oracle. Use getPriceData(key) method to get price data about a specific key.

Price data structure contains:

struct PriceData {  
    uint8 data; // not in use, reserved for future  
    uint24 heartbeat; // if price is flat, how often it will be updated  
    uint32 timestamp; // last update  
    uint128 price; // 8 decimals  
}

Via reader

There is the option to create dedicated contract reader which emulates interface of other leader oracles. As a first stage, we are implementing a contract with a Chainlink-like interface..

In order to instantiate a new Reader contract for a given data point:

  1. Go to TripleFeedsReaderFactorysmart contract and use the deployed(key) method to check whether there is already a Reader contract for your key.

📘

TripleFeedsReaderFactory smart contract address can be retrieved from the Registry using the TripleFeedsReaderFactory keyword.

  1. if a Reader method for your key hasn't beed instantiated, use the TripleFeedsReaderFactory.deploy(key) method to create a new instance of the TripleFeedsReader contract, dedicated for provided key.

    1. Use deployed(key) method to read address of deployed contract.

    2. In case contract code is not verified automatically, you can use (TripleFeedsReader standard JSON)[./flattened/TripleFeedsReader.stdandard.json] to verify its code.

TripleFeedsReader provides few methods that you can use depending on the case:

  • latestRoundData(): it follows chainlink interface to easier migration process from Chainlink to Triple.

🚧

IMPORTANT

Only answer and updatedAtfield are in use.

  • getPriceData(): it returns PriceData.

Fallback mechanism

A fallback mechanism has been included in the TripleFeedsReader smart contract to ensure you always read data from the latest TripleFeeds contract.

Like a Proxy

While proxy contracts are forced to read implementation address all the time, the fallback mechanism searches for a new address ONLY when it is needed, and only then, additional cost is added to the transaction.

Redeployments of contracts are very rare, so it is more effective to simply update contract address when needed than paying additional fee every time we read the price.

If you chose to read prices directly from the TripleFeeds contract, you will need to implement a mechanism similar to the fallback on your side. You can check the implementation of the TripleFeedsReaderFactory smart contract as an example.

Last updated