DIVA Protocol
  • 👋Welcome
  • 🔅Introduction
    • Derivative contracts
    • What is DIVA Protocol
      • What problem does it solve
      • How it works
        • Reference assets
        • Payoff curves
        • Collateral
        • Oracles
        • Settlement
          • Timelines
          • Challenge
          • Status
          • Fast settlement
          • Fallback data provider
        • Fees
        • Compliance feature
      • Vision
      • Terminology
    • What is DIVA Token
      • Owner election mechanism
      • Token distribution
    • DIVA Development Fund
    • FAQ
  • 🌈DIVA App
    • What is DIVA App
    • Overview
    • Create position tokens
    • Trade position tokens
    • Add liquidity
    • Remove liquidity
  • ⚙️Guides
    • DIVA App Training
      • Prepare
      • Testnet
      • Create
      • Trade
      • Add
      • Remove
      • Settle
      • Redeem
      • Fees
    • Quiz
  • 🪄Use cases
    • Overview
    • Insurance
      • Credit default protection
      • Agrarian insurance
      • DeFi Hack insurance
      • Peg insurance
    • Yield optimization
      • Bullish accumulation
      • Bearish accumulation
    • Risk management
      • Downside protection
      • Increasing cost protection
    • Directional bets
      • Downside bet
      • "Bottom-Is-In" bet
      • Upside bet
      • "Top-Is-In" bet
    • Leverage
  • 👨‍🎓Pricing derivatives
    • Introduction
    • Underlying value
    • Volatility
    • Time
  • ⚓Oracle integrations
    • Overview
    • Tellor
  • ⚒️For developers
    • Overview
    • Technical resources
    • Smart contracts
      • Functions
        • Core protocol functions
        • Getter functions
        • Setter functions
        • ABI
      • Contract addresses
      • Example scripts
    • TheGraph
      • DIVA subgraphs
      • Whitelist subgraph
    • Project ideas
  • 📱Contact & Media Links
    • Social media
  • 👨‍🎓Technical Blog
    • Flash loans in DIVA Protocol
    • NDVI outcome reporting guide for Tellor Reporters
    • Enabling capital efficiency in DeFi
Powered by GitBook
On this page
  • Pool data
  • Data providers
  • Fees
  • Challenge
  • User positions
  1. For developers
  2. TheGraph

DIVA subgraphs

PreviousTheGraphNextWhitelist subgraph

Last updated 2 years ago

Data emitted as the result of DIVA smart contract interactions is indexed using TheGraph.

The DIVA subgraph can be accessed here:

  • Ropsten (deprecated):

  • Goerli:

Pool data

The following query can be used to pull the data for a given pool Id (here pool Id = 5):

{
  pools(where: {id: 5}) {
    id
    referenceAsset
    floor
    inflection
    cap
    supplyInitial
    supplyShort
    supplyLong
    expiryTime
    collateralToken {
      id
      name
      symbol
      decimals
    }
    collateralBalanceShortInitial
    collateralBalanceLongInitial
    collateralBalance
    shortToken {
      id
      name
      symbol
      decimals
    }
    longToken {
      id
      name
      symbol
      decimals
    }
    finalReferenceValue
    statusFinalReferenceValue
    redemptionAmountLongToken
    redemptionAmountShortToken
    statusTimestamp
    dataProvider
    redemptionFee
    settlementFee
    createdBy
    createdAt
    
  }
}

Sample output from the above query:

{
  "data": {
    "pools": [
      {
        "id": "5",
        "referenceAsset": "ETH/USD",
        "floor": "2000000000000000000000",
        "inflection": "2000000000000000000000",
        "cap": "4500000000000000000000",
        "supplyInitial": "100000000000000000000",
        "supplyShort": "100000000000000000000",
        "supplyLong": "100000000000000000000",
        "expiryTime": "1647363501",
        "collateralToken": {
          "id": "0x867e53fede91d27101e062bf7002143ebaea3e30",
          "name": "WAGMI18",
          "symbol": "WAGMI18",
          "decimals": 18
        },
        "collateralBalanceShortInitial": "50000000000000000000",
        "collateralBalanceLongInitial": "50000000000000000000",
        "collateralBalance": "100000000000000000000",
        "shortToken": {
          "id": "0x4f946061de10a369de7e689f368053959a67a58e",
          "name": "S5",
          "symbol": "S5",
          "decimals": 18
        },
        "longToken": {
          "id": "0x33aa4370599755b83915dcc87c8eced8a5b9b1d2",
          "name": "L5",
          "symbol": "L5",
          "decimals": 18
        },
        "finalReferenceValue": "80000000000000000000",
        "statusFinalReferenceValue": "Challenged",
        "redemptionAmountLongToken": "0",
        "redemptionAmountShortToken": "0",
        "statusTimestamp": "1647381997",
        "dataProvider": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
        "redemptionFee": "2500000000000000",
        "settlementFee": "500000000000000",
        "createdBy": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
        "createdAt": "1647363941"
      }
    ]
  }
}

Data providers

Data providers that want to listen to pools where they are selected as the data provider can use the following reduced version of the pool query (here using address 0x9adefeb576dcf52f5220709c1b267d89d5208d78 as the data provider, all in small letters):

{
  pools (where: {dataProvider: "0x9adefeb576dcf52f5220709c1b267d89d5208d78"}) {
    id
    dataProvider
    referenceAsset
    floor
    inflection
    cap
    expiryTime
    createdAt
  }
}

Sample output of the above query:

{
  "data": {
    "pools": [
      {
        "id": "10",
        "dataProvider": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
        "referenceAsset": "BTC/USD",
        "floor": "60000000000000000000000",
        "inflection": "70000000000000000000000",
        "cap": "90000000000000000000000",
        "expiryTime": "1648112254",
        "createdAt": "1648022403"
      },
      {
        "id": "13",
        "dataProvider": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
        "referenceAsset": "BTC/USD",
        "floor": "40000000000000000000000",
        "inflection": "60000000000000000000000",
        "cap": "80000000000000000000000",
        "expiryTime": "1651269610",
        "createdAt": "1648197988"
      }
    ]
  }
}

Fees

Query to pull the fee claims for a given address (has to be lower case!):

feeRecipients(where: {id: "0x9adefeb576dcf52f5220709c1b267d89d5208d78"}) {
    id
    collateralTokens {
      amount
      collateralToken {
        id
        name
        symbol
        decimals
      }
    }
  }

Sample output from the above query:

{
  "data": {
    "feeRecipients": [
      {
        "id": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
        "collateralTokens": [
          {
            "amount": "32695586760280840",
            "collateralToken": {
              "id": "0x867e53fede91d27101e062bf7002143ebaea3e30",
              "name": "WAGMI18",
              "symbol": "WAGMI18"
            }
          },
          {
            "amount": "30000",
            "collateralToken": {
              "id": "0x8ca8de48c4507fa54a83dde7ac68097e87520eec",
              "name": "WAGMI6",
              "symbol": "WAGMI6"
            }
          }
        ]
      }
    ]
  }
}

Challenge

Query to retrieve the submitted challenges for a given poolId (here poolId = 5):

{
  challenges(where: {pool: "5"}) {
    challengedBy
    proposedFinalReferenceValue
    pool {
      id
    }
  }
}

Sample output of above query:

{
  "data": {
    "challenges": [
      {
        "challengedBy": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
        "proposedFinalReferenceValue": "1670000000000000000000",
        "pool": {
          "id": "5"
        }
      }
    ]
  }
}

User positions

Query to retrieve a shortlist of position tokens that a user may own. The shortlist is constructed based on user interactions with the DIVA Protocol functions as well as 0x protocol. Note that position tokens received via different avenues (e.g., Uniswap or simple transfer) will not appear in the list.

{
  user(id: "0x9adefeb576dcf52f5220709c1b267d89d5208d78" ){
    id
    positionTokens(first: 100,
      orderDirection: desc,
      orderBy: receivedAt,) {
        receivedAt,
        positionToken {
        id
        name
        symbol
        decimals
        owner
        pool {
          id
          referenceAsset
          floor
          inflection
          cap
          supplyInitial
          supplyShort
          supplyLong
          expiryTime
          collateralToken {
            id
            name
            decimals
            symbol
          }
  				collateralBalanceLongInitial
          collateralBalanceShortInitial
          collateralBalance
          shortToken {
            id
            name
            symbol
            decimals
            owner
          }
          longToken {
            id
            name
            symbol
            decimals
            owner
          }
          finalReferenceValue
          statusFinalReferenceValue
          redemptionAmountLongToken
          redemptionAmountShortToken
          statusTimestamp
          dataProvider
          redemptionFee
          settlementFee
          createdBy
          createdAt
          capacity
          expiryTime
          challenges {
            challengedBy
            proposedFinalReferenceValue
          }
        }
      }
    }
  }
}

Sample output of above query

{
  "data": {
    "user": {
      "id": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
      "positionTokens": [
        {
          "receivedAt": "1660894980",
          "positionToken": {
            "id": "0xac9bfbeadb47ab2bd8013eb61e1a636fe04aaeb1",
            "name": "S54459",
            "symbol": "S54459",
            "decimals": 18,
            "owner": "0xebbaa31b1ebd727a1a42e71dc15e304ad8905211",
            "pool": {
              "id": "54459",
              "referenceAsset": "REP/USD",
              "floor": "10000000000000000000",
              "inflection": "15000000000000000000",
              "cap": "20000000000000000000",
              "supplyInitial": "10000000000000000000",
              "supplyShort": "10000000000000000000",
              "supplyLong": "10000000000000000000",
              "expiryTime": "1660895400",
              "collateralToken": {
                "id": "0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355",
                "name": "DIVA USD",
                "decimals": 18,
                "symbol": "dUSD"
              },
              "collateralBalanceLongInitial": "5000000000000000000",
              "collateralBalanceShortInitial": "5000000000000000000",
              "collateralBalance": "10000000000000000000",
              "shortToken": {
                "id": "0xac9bfbeadb47ab2bd8013eb61e1a636fe04aaeb1",
                "name": "S54459",
                "symbol": "S54459",
                "decimals": 18,
                "owner": "0xebbaa31b1ebd727a1a42e71dc15e304ad8905211"
              },
              "longToken": {
                "id": "0x88f4b382c2777ac2ba2e3b5c4e7c1d0215074aed",
                "name": "L54459",
                "symbol": "L54459",
                "decimals": 18,
                "owner": "0xebbaa31b1ebd727a1a42e71dc15e304ad8905211"
              },
              "finalReferenceValue": "0",
              "statusFinalReferenceValue": "Open",
              "redemptionAmountLongToken": "0",
              "redemptionAmountShortToken": "0",
              "statusTimestamp": "1660894980",
              "dataProvider": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
              "redemptionFee": "2500000000000000",
              "settlementFee": "500000000000000",
              "createdBy": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
              "createdAt": "1660894980",
              "capacity": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
              "challenges": []
            }
          }
        },
        {
          "receivedAt": "1660894980",
          "positionToken": {
            "id": "0x88f4b382c2777ac2ba2e3b5c4e7c1d0215074aed",
            "name": "L54459",
            "symbol": "L54459",
            "decimals": 18,
            "owner": "0xebbaa31b1ebd727a1a42e71dc15e304ad8905211",
            "pool": {
              "id": "54459",
              "referenceAsset": "REP/USD",
              "floor": "10000000000000000000",
              "inflection": "15000000000000000000",
              "cap": "20000000000000000000",
              "supplyInitial": "10000000000000000000",
              "supplyShort": "10000000000000000000",
              "supplyLong": "10000000000000000000",
              "expiryTime": "1660895400",
              "collateralToken": {
                "id": "0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355",
                "name": "DIVA USD",
                "decimals": 18,
                "symbol": "dUSD"
              },
              "collateralBalanceLongInitial": "5000000000000000000",
              "collateralBalanceShortInitial": "5000000000000000000",
              "collateralBalance": "10000000000000000000",
              "shortToken": {
                "id": "0xac9bfbeadb47ab2bd8013eb61e1a636fe04aaeb1",
                "name": "S54459",
                "symbol": "S54459",
                "decimals": 18,
                "owner": "0xebbaa31b1ebd727a1a42e71dc15e304ad8905211"
              },
              "longToken": {
                "id": "0x88f4b382c2777ac2ba2e3b5c4e7c1d0215074aed",
                "name": "L54459",
                "symbol": "L54459",
                "decimals": 18,
                "owner": "0xebbaa31b1ebd727a1a42e71dc15e304ad8905211"
              },
              "finalReferenceValue": "0",
              "statusFinalReferenceValue": "Open",
              "redemptionAmountLongToken": "0",
              "redemptionAmountShortToken": "0",
              "statusTimestamp": "1660894980",
              "dataProvider": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
              "redemptionFee": "2500000000000000",
              "settlementFee": "500000000000000",
              "createdBy": "0x9adefeb576dcf52f5220709c1b267d89d5208d78",
              "createdAt": "1660894980",
              "capacity": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
              "challenges": []
            }
          }
        },
        {...},
        {...}
      ]
    }
  }
}
⚒️
https://thegraph.com/hosted-service/subgraph/divaprotocol/diva-ropsten
https://thegraph.com/hosted-service/subgraph/divaprotocol/diva-goerli