|
| 1 | +!!! info "Content disclaimer" |
| 2 | + |
| 3 | + Please view the third-party content disclaimer [here](https://github.com/0xPolygon/polygon-docs/blob/main/CONTENT_DISCLAIMER.md). |
| 4 | + |
| 5 | +# Supra Oracle Integration |
| 6 | + |
| 7 | +**Supra** is a MultiVM Layer 1 network designed for high performance, interoperability, and security. It has achieved over **500,000 transactions per second (TPS)** across **300 nodes** with **sub-second consensus latency**, marking it as one of the fastest and most scalable Layer 1 solutions available. Supra is also the first blockchain to provide full vertical integration of **native oracles, DVRF, bridging, and automation**, enabling developers to build powerful **Super dApps** within a unified ecosystem. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Key Features |
| 12 | + |
| 13 | +### Lightning Fast Speeds |
| 14 | +Supra provides near-instant data refresh rates with full on-chain finality, reaching consensus in **600–900 milliseconds**. This makes it one of the **fastest-to-finality oracle networks** available. |
| 15 | + |
| 16 | +### Truly Decentralized |
| 17 | +Supra’s oracles are decentralized at every level—from **multi-source data collection** to a **globally distributed node network**—ensuring reliability and trustless data delivery. |
| 18 | + |
| 19 | +### Toughened Security |
| 20 | +A randomized node network and built-in fail-safes help **maximize security** and prevent manipulation or downtime. |
| 21 | + |
| 22 | +### Natively Interoperable |
| 23 | +Supra is **blockchain agnostic**, offering compatibility with **58+ networks** including **Polygon, Ethereum, Arbitrum, Optimism, Avalanche, and Aptos**, among others. |
| 24 | + |
| 25 | +### Massive Scalability |
| 26 | +Supra’s novel consensus mechanism enables **hundreds of thousands of transactions per second** without sacrificing security or decentralization. |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## Supra Oracle Resources |
| 31 | + |
| 32 | +Explore Supra’s documentation for more information on: |
| 33 | + |
| 34 | +- [**Data Feeds**](#) |
| 35 | +- [**APIs for Real-Time and Historical Data**](#) |
| 36 | +- [**Indices**](#) |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +# Pull Oracle Integration |
| 41 | + |
| 42 | +Supra’s **Pull Oracle** allows developers to retrieve proof data directly from a gRPC server and interact with smart contracts programmatically. |
| 43 | + |
| 44 | +## Installation |
| 45 | + |
| 46 | +Clone the repository or download the source code, then install the required dependencies: |
| 47 | + |
| 48 | +```bash |
| 49 | +npm install |
| 50 | +``` |
| 51 | + |
| 52 | +## Configuration |
| 53 | + |
| 54 | +Before using the library, configure the parameters in your `main.js` file. |
| 55 | + |
| 56 | +### gRPC Server Address |
| 57 | + |
| 58 | +**Mainnet:** |
| 59 | +``` |
| 60 | +mainnet-dora-2.supra.com:443 |
| 61 | +``` |
| 62 | + |
| 63 | +**Testnet:** |
| 64 | +``` |
| 65 | +testnet-dora-2.supra.com:443 |
| 66 | +``` |
| 67 | + |
| 68 | +### REST Server Address |
| 69 | + |
| 70 | +**Mainnet:** |
| 71 | +``` |
| 72 | +https://rpc-mainnet-dora-2.supra.com |
| 73 | +``` |
| 74 | + |
| 75 | +**Testnet:** |
| 76 | +``` |
| 77 | +https://rpc-testnet-dora-2.supra.com |
| 78 | +``` |
| 79 | + |
| 80 | +### Pair Indexes |
| 81 | + |
| 82 | +Set the desired pair indexes as an array (example): |
| 83 | + |
| 84 | +```javascript |
| 85 | +const pairIndexes = [0, 21, 61, 49]; |
| 86 | +``` |
| 87 | + |
| 88 | +### Chain Type |
| 89 | + |
| 90 | +Specify the chain type as EVM: |
| 91 | + |
| 92 | +```javascript |
| 93 | +const chainType = 'evm'; |
| 94 | +``` |
| 95 | + |
| 96 | +### RPC Configuration |
| 97 | + |
| 98 | +Set the RPC URL for your target blockchain network: |
| 99 | + |
| 100 | +```javascript |
| 101 | +const web3 = new Web3(new Web3.providers.HttpProvider('<RPC URL>')); |
| 102 | +``` |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## Customization |
| 107 | + |
| 108 | +You can modify the smart contract interaction logic within the `callContract` function. |
| 109 | + |
| 110 | +### Smart Contract ABI |
| 111 | + |
| 112 | +Update the path to your ABI JSON file: |
| 113 | + |
| 114 | +```javascript |
| 115 | +const contractAbi = require("../resources/abi.json"); |
| 116 | +``` |
| 117 | + |
| 118 | +### Smart Contract Address |
| 119 | + |
| 120 | +Specify your contract address: |
| 121 | + |
| 122 | +```javascript |
| 123 | +const contractAddress = '<CONTRACT ADDRESS>'; |
| 124 | +``` |
| 125 | + |
| 126 | +### Function Call |
| 127 | + |
| 128 | +Modify the function call as per your contract. Example: |
| 129 | + |
| 130 | +```javascript |
| 131 | +const txData = contract.methods.GetPairPrice(hex, 0).encodeABI(); |
| 132 | +``` |
| 133 | + |
| 134 | +### Gas Estimation |
| 135 | + |
| 136 | +Estimate gas for your function call: |
| 137 | + |
| 138 | +```bash |
| 139 | +const gasEstimate = await contract.methods.GetPairPrice(hex, 0).estimateGas({ from: "<WALLET ADDRESS>" }); |
| 140 | +``` |
| 141 | + |
| 142 | +### Transaction Object |
| 143 | + |
| 144 | +Customize the transaction parameters: |
| 145 | + |
| 146 | +```bash |
| 147 | +const transactionObject = { |
| 148 | + from: "<WALLET ADDRESS>", |
| 149 | + to: contractAddress, |
| 150 | + data: txData, |
| 151 | + gas: gasEstimate, |
| 152 | + gasPrice: await web3.eth.getGasPrice() |
| 153 | +}; |
| 154 | +``` |
| 155 | + |
| 156 | +### Private Key Signing |
| 157 | + |
| 158 | +Sign the transaction using your private key: |
| 159 | + |
| 160 | +```bash |
| 161 | +const signedTransaction = await web3.eth.accounts.signTransaction(transactionObject, "<PRIVATE KEY>"); |
| 162 | +``` |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## Running the Application |
| 167 | + |
| 168 | +To start the application and initiate proof data fetching, run: |
| 169 | + |
| 170 | +```bash |
| 171 | +node main.js |
| 172 | +``` |
| 173 | + |
| 174 | +This will retrieve data from Supra’s servers and interact with your smart contract using the defined configurations. |
| 175 | + |
| 176 | +--- |
| 177 | + |
| 178 | +# Push Oracle Integration |
| 179 | + |
| 180 | +Supra’s **Push Oracle** enables on-chain access to real-time data feeds (S-Values) through Solidity interfaces. |
| 181 | + |
| 182 | +## Step 1: Create the S-Value Interface |
| 183 | + |
| 184 | +Add the following code to your contract to define the data structures and functions needed to retrieve S-Values: |
| 185 | + |
| 186 | +```solidity |
| 187 | +pragma solidity 0.8.19; |
| 188 | +
|
| 189 | +interface ISupraSValueFeed { |
| 190 | + struct priceFeed { |
| 191 | + uint256 round; |
| 192 | + uint256 decimals; |
| 193 | + uint256 time; |
| 194 | + uint256 price; |
| 195 | + } |
| 196 | +
|
| 197 | + struct derivedData { |
| 198 | + int256 roundDifference; |
| 199 | + uint256 derivedPrice; |
| 200 | + uint256 decimals; |
| 201 | + } |
| 202 | +
|
| 203 | + function getSvalue(uint256 _pairIndex) external view returns (priceFeed memory); |
| 204 | +
|
| 205 | + function getSvalues(uint256[] memory _pairIndexes) external view returns (priceFeed[] memory); |
| 206 | +
|
| 207 | + function getDerivedSvalue(uint256 pair_id_1, uint256 pair_id_2, uint256 operation) |
| 208 | + external |
| 209 | + view |
| 210 | + returns (derivedData memory); |
| 211 | +
|
| 212 | + function getTimestamp(uint256 _tradingPair) external view returns (uint256); |
| 213 | +} |
| 214 | +``` |
| 215 | + |
| 216 | +--- |
| 217 | + |
| 218 | +## Step 2: Configure the S-Value Feed Address |
| 219 | + |
| 220 | +Initialize the S-Value feed contract in your smart contract constructor: |
| 221 | + |
| 222 | +```solidity |
| 223 | +contract ISupraSValueFeedExample { |
| 224 | + ISupraSValueFeed internal sValueFeed; |
| 225 | +
|
| 226 | + constructor() { |
| 227 | + sValueFeed = ISupraSValueFeed(0xE92D276bBE234869Ecc9b85101F423c6bD26654A); |
| 228 | + } |
| 229 | +} |
| 230 | +``` |
| 231 | + |
| 232 | +*Note: Replace the above address with the correct network-specific Supra contract address.* |
| 233 | + |
| 234 | +--- |
| 235 | + |
| 236 | +## Step 3: Retrieve the S-Value Data |
| 237 | + |
| 238 | +Use the following functions to fetch single or multiple S-Values and to derive new data pairs. |
| 239 | + |
| 240 | +```solidity |
| 241 | +function getPrice(uint256 _priceIndex) |
| 242 | + external |
| 243 | + view |
| 244 | + returns (ISupraSValueFeed.priceFeed memory) |
| 245 | +{ |
| 246 | + return sValueFeed.getSvalue(_priceIndex); |
| 247 | +} |
| 248 | +
|
| 249 | +function getPriceForMultiplePair(uint256[] memory _pairIndexes) |
| 250 | + external |
| 251 | + view |
| 252 | + returns (ISupraSValueFeed.priceFeed[] memory) |
| 253 | +{ |
| 254 | + return sValueFeed.getSvalues(_pairIndexes); |
| 255 | +} |
| 256 | +
|
| 257 | +function getDerivedValueOfPair(uint256 pair_id_1, uint256 pair_id_2, uint256 operation) |
| 258 | + external |
| 259 | + view |
| 260 | + returns (ISupraSValueFeed.derivedData memory) |
| 261 | +{ |
| 262 | + return sValueFeed.getDerivedSvalue(pair_id_1, pair_id_2, operation); |
| 263 | +} |
| 264 | +``` |
| 265 | + |
| 266 | +--- |
| 267 | + |
| 268 | +## Recommended Best Practices |
| 269 | + |
| 270 | +Implement an **access-controlled function** to update the Supra feed contract address for future upgrades: |
| 271 | + |
| 272 | +```solidity |
| 273 | +function updateSupraSvalueFeed(ISupraSValueFeed _newSValueFeed) |
| 274 | + external |
| 275 | + onlyOwner |
| 276 | +{ |
| 277 | + sValueFeed = _newSValueFeed; |
| 278 | +} |
| 279 | +``` |
| 280 | + |
| 281 | +This approach ensures your contract remains upgradeable while maintaining secure access control over Oracle configurations. |
| 282 | + |
| 283 | +--- |
| 284 | + |
| 285 | +By integrating **Supra Oracles**, developers gain access to a high-speed, decentralized, and secure data layer—purpose-built for real-world use cases across DeFi, gaming, and Web3 applications. |
0 commit comments