Integrating Push Model

Getting Started with Triple Price Feeds Incorporating Triple Oracles' price feeds into your project is a straightforward process. Triple Oracles currently provides support for numerous EVM-based networks. The value of the price feed published by Triple is referred to as 'Triple-Value.' In the following sections, we will illustrate how to access and retrieve Triple-Value from Triple.

Step 1: Create The Triple-Value Interface

In the first step you need to build data structures to receive the data feeds and functions to fetch data into configured data structures. You may add the following code to the solidity smart contract that you wish to retrieve Triple-Value.

pragma solidity 0.8.19;

// depending on the requirement, you may build one or more 
// data structures given below. 

interface ITripleValueFeed {

// Data structure to hold the pair data
struct dataWithoutHcc {
uint256 round;
uint256 decimals;
uint256 time;
uint256 price;
}

// Data structure to hold the pair data with History Consistency Check
struct dataWithHcc {
uint256 round;
uint256 decimals;
uint256 time;
uint256 price;
uint256 historyConsistent;
}

// Data structure to hold the derived pair data 
struct derivedData{
int256 roundDifference;
int256 timeDifference;
uint256 derivedPrice;
uint256 decimals;
}

// Below functions enable you to retrieve different flavours of S-Value

// Function to fetch the data for a single data pair
function getTriplevalues(uint256 _pairIndex)
external
view
returns (dataWithoutHcc memory);

//Function to fetch the data for a multiple data pairs
function getTriplevalues(uint256[] memory _pairIndexes)
external
view
returns (dataWithoutHcc[] memory);

// Function to Fetch the Data for a single data pair with HCC
function getTriplevaluesWithHCC(uint256 _pairIndex)
external
view
returns (dataWithHcc memory);

// Function to Fetch the Data for a multiple data pairs with HCC
function getTriplevaluesWithHCC(uint256[] memory _pairIndexes)
external
view
returns (dataWithHcc[] memory);

// Function to fetch the data for a derived data pair.
function getDerivedTriplevalues(uint256 _derivedPairId)
external
view
returns (derivedData memory);

// Function to fetch the timestamp(Last or Latest) of the data pair
// If you need to check the staleness of the data prior to requesting S-values
// use this function to check the last updated time stamp of the data pair.
  
function getTimestamp(uint256 _tradingPair) 
external
view
returns (uint256);

Above creates the interface that you will later apply in order to fetch a price from Triple Oracles.

Step 2: Configure The Triple-Value Feed Address

In order to retrieve the Triple-Value, then configure Triple-Value feed using the Triple Smart Contract address as demonstrated below.

contract ITripleValueFeedExample {
   ITripleValueFeedd internal sValueFeed;
    constructor() {
        sValueFeed = ITripleValueFeed(0xE66683874hd84008847hf6654A);
    }
} 

Step 3: Get The Triple-Value Crypto Price

Now you can access the Triple-Value for any of the trading pairs Triple publishes. Below sample code retrieves Triple-Value for single as well as multiple data pairs for demonstration purpose. You may use it as appropriate.

// requesting Triple-Value for a single pair
function getPrice(uint256 _priceIndex)
external
view 
returns (ITripleValueFeed.dataWithoutHcc memory) {
return TripleValueFeed.getTriplevalue(_priceIndex);
}

// requesting Triple-values for multiple pairs
function getPriceForMultiplePair(uint256[] memory _pairIndexes) 
external 
view 
returns (ITripleValueFeed.dataWithoutHcc[] memory) {
return TripleValueFeed.getTriplevalues(_pairIndexes);
}
 
// Requesting Triple-value for a single data pair with HCC check. 
function getPriceWithHccCheck (uint256 _priceIndex) 
external 
view 
returns (ITripleValueFeed.dataWithHcc memory) {
return TripleFeed.getTriplevalueWithHCC(_priceIndex);
}

// Requesting Triple-values for multiple pairs with HCC check. 
function getPriceWithHccCheckForMultiplePair(uint256[] memory _pairIndexes) 
external
view 
returns (ITripleValueFeed.dataWithHcc[] memory) {
return TripleValueFeed.getTriplevaluesWithHCC(_pairIndexes);
}

// Requesting value of a derived data pair 
function getDerivedValueOfPairId(uint256 _derivedPairId) 
external
view returns(ITripleValueFeed.derivedData memory){
return TripleFeed.getDerivedTriplevalue(_derivedPairId);
}

Last updated