npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pragmaoracle/solidity-sdk

v1.0.1

Published

Solidity contracts of the Pragma protocol.

Downloads

37

Readme

Pragma Solidity SDK

This package provides the interfaces and structs that can be used in your solidity contracts to interact with Pragma core contract.

Installation

Foundry

# Install Foundry (Forge)
curl -L https://foundry.paradigm.xyz | bash
foundryup

# Install the Solidity SDK for Forge
forge install @pragmaoracle/solidity-sdk

Hardhat

# Install Hardhat globally
npm install --save-dev hardhat

# Install the Solidity SDK for Hardhat
npm install @pragmaoracle/solidity-sdk

Example Usage

pragma solidity ^0.8.0;
 
import "@pragmaoracle/solidity-sdk/IPragma.sol";
import "@pragmaoracle/solidity-sdk/PragmaStructs.sol";
 
contract YourContract {
  IPragma oracle;
 
  /**
   * @param pragmaContract The address of the Pragma contract
   */
  constructor(address pragmaContract) {
    // The IPragam interface from the sdk provides the methods to interact with the Pragma contract.
    oracle = IPragma(pragmaContract);
  }
 
  /**
     * This method is an example of how to interact with the Pragma contract to fetch Spot Median updates. You can check the documentation to 
     * find the available feeds.
     * @param priceUpdate The encoded data to update the contract with the latest price
     */
  function yourFunction(bytes[] calldata priceUpdate) public payable {
    // Submit a priceUpdate to the Pragma contract to update the on-chain price.
    // Updating the price requires paying the fee returned by getUpdateFee.
    uint fee = oracle.getUpdateFee(priceUpdate);
    oracle.updatePriceFeeds{ value: fee }(priceUpdate);
 
    // Read the current price from a price feed if it is less than 60 seconds old.
    // Each price feed (e.g., Spot Median ETH/USD) is identified by a unique identifier id.
    bytes32 id = 0x4554482f555344; // ETH/USD
    PragmaStructs.DataFeed memory data_feed = oracle.getSpotMedianNoOlderThan(id, 60);
  }

}

Let's detail the operations done by the snippet above. Firstly we instantiate a IPragma interface from the solidity SDK, linked to a Pragma contract, passed in the constructor.
Then we call IPragma.getUpdateFee to determine the fee charged to update the price.
After calling IPragma.updatePriceFeeds to update the price, paying the previous fee, we call IPragma.getSpotMedianNoOlderThan to read the current spot median price for the given feed id providing an acceptable staleness for the data to be fetched. You can find here the list of available feeds.

Integration by copying the Pragma interface

Alternatively, you can copy the IPragma.sol interface and PragmaStructs.sol inside your repository, and generate an instance using a deployed Pragma contract.

import {IPragma} from "./interfaces/IPragma.sol";
import PragmaStructs from "./interfaces/PragmaStructs.sol";

The rest remains the same as described above.

Available feeds

You can now use various methods to fetch data from the Pragma oracle. Here are the main functions:

  • getSpotMedianNoOlderThan(bytes32 id, uint256 age)
  • getTwapNoOlderThan(bytes32 id, uint256 age)
  • getRealizedVolatilityNoOlderThan(bytes32 id, uint256 age)
  • getOptionsNoOlderThan(bytes32 id, uint256 age)
  • getPerpNoOlderThan(bytes32 id, uint256 age)