Quickstart
This guide contains sample snippets to help you get started consuming data feeds from Upshot
The code repository can be found here.
Consuming Data Feeds from Upshot
Below is an example of requesting a price from Upshot. This example code can be found here: https://github.com/upshot-tech/upshot-oracle-v2/blob/main/src/examples/OracleUserExample.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import { IOracle, Feed, FeedView, UpshotOracleNumericData } from '../interface/IOracle.sol';
import { Ownable2Step } from "../../lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol";
import { EnumerableSet } from "../../lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol";
/**
* @title OraclePriceExample
* @notice Example contract for using the Upshot Oracle for prices
*/
contract OraclePriceExample is Ownable2Step {
// Sepolia oracle Address
IOracle public upshotOracle = IOracle(0xA610B62931659779ad06821FFEfEDc48AF087C88);
constructor () {
_transferOwnership(msg.sender);
}
// ***************************************************************
// * ================== USER INTERFACE ========================= *
// ***************************************************************
/**
* @notice Example for calling a protocol function with a price from the Upshot Oracle
*
* @param protocolFunctionArgument An argument for the protocol function
* @param upshotOracleData The signed data from the Upshot Oracle
*/
function callProtocolFunctionWithUpshotOraclePrice(
uint256 protocolFunctionArgument,
UpshotOracleNumericData calldata upshotOracleData
) external payable {
uint256 price = upshotOracle.verifyData{value: msg.value}(upshotOracleData);
_protocolFunctionRequiringPrice(protocolFunctionArgument, price);
}
function _protocolFunctionRequiringPrice(uint256 protocolFunctionArgument, uint256 price) internal {
// use arguments and price
}
// ***************************************************************
// * ========================= ADMIN =========================== *
// ***************************************************************
/**
* @notice Set the Upshot Oracle contract address
*
* @param upshotOracle_ The Upshot Oracle contract address
*/
function setUpshotOracleContract(IOracle upshotOracle_) external onlyOwner {
upshotOracle = upshotOracle_;
}
}
Feed Management
When creating or modifying a feed, Upshot allows the following customizations:
- Total Fee
- Fee Distribution logic
- Aggregation logic, common choices include Average and Median
- Minimum number of price providers
- Price validity time duration
Updated 22 days ago