LogoLogo
TwitterTelegramDiscordMedium
  • 👋Welcome to DFX Finance
  • Protocol
    • 🏭DFX AMM
    • 🏛️Protocol Governance
      • 🗳️Proposal Process
        • Proposal Forum
        • Proposal Template
        • Vote on Proposals
      • 🪙DFX Token
      • 🪙veDFX
        • 🔐Lock Details
          • 🔒How to Lock?
        • 🎛️Gauges
        • 🚀Boost
      • 📸Snapshot
    • ⛏️Liquidity Mining
      • 🤔What is Liquidity Mining?
      • ➕How to Supply Liquidity
      • 💱Swaps & Liquidity Pools
      • 📊Current Yield Rates
    • 🧠Education Zone
      • ❔What is DFX?
        • 🇨🇳什么是 DFX Finance
        • 🇳🇱Wat is DFX Finance?
        • 🇫🇷Le protocole DFX Finance?
        • 🇩🇪Was ist DFX Finance?
        • 🇮🇱מהו DFX פיננסים?
        • 🇮🇳DFX फाइनेंस क्या है?
        • 🇵🇹O que é DFX Finance?
        • 🇪🇸Que es DFX?
        • 🇮🇳DFX పరిచయం
        • 🇹🇷DFX Finans Nedir ?
      • ➕How to Supply Liquidity
      • 💱Swaps & Liquidity Pools
      • 🔒How to Lock?
      • 🔗Migrate from V1 to V2
    • 🏆DFX Grants Program
      • 🐲Ambassador Program
  • Dev Zone
    • 🕸️Subgraphs
      • Entities
      • Queries
      • 📖Read Me
    • 📃Smart Contracts
      • 3️⃣𝓥3
      • 2️⃣V2
    • 📃Deprecated Smart Contracts
  • Stablecoins
    • 🇺🇸USDC
    • 🇨🇦CADC
    • 🇪🇺EURC
    • 🇬🇧GBPT
    • 🇯🇵GYEN
    • 🇳🇬NGNC
    • 🇹🇷TRYB
    • 🇸🇬XSGD
    • 🇮🇩XIDR
  • Communities
    • X (Formally Twitter)
    • Medium
    • Discord
    • Telegram
    • LinkedIn
  • FAQs
    • ❔General Questions
    • 🏭Create Pools
    • 🪙DFX Migration / Bridge
    • 📊Analytics
    • 💸 KPI Options
    • 🌌Reimbursement Plan
    • 📰DFX Media Kit
    • ✅Protocol Audits
Powered by GitBook
On this page
  • DFX V1 Subgraph
  • Ethereum (Mainnet)
  • Polygon
  • Setup
  • Deploy
  • Deploy Legacy Explorer (Hosted)
  • Documentation
  • Debugging
  • Common issues:
  • Logging

Was this helpful?

  1. Dev Zone
  2. Subgraphs

Read Me

All information here is source from the official DFX Finance GitHub.

PreviousQueriesNextSmart Contracts

Last updated 1 year ago

Was this helpful?

DFX V1 Subgraph

Any USD base pair created by the is tracked by this subgraph. The subgraph tracks DFX for daily and hourly historical data on TVLs and volumes.

Currently there are 6 USD based stablecoin pairs on Ethereum (Mainnet) and 5 on Polygon.

DFX Subgraph Source:


Ethereum (Mainnet)

  • Singapore -

  • Europe -

  • Canada -

  • New Zealand -

  • Turkey -

  • Indonesia -

Polygon

  • Singapore -

  • Europe -

  • Canada -

  • Turkey -


Setup

  1. Go to https://thegraph.com/studio/

  2. Connect your MetaMask wallet and sign (This will not cost you any ETH)

  3. Create a subgraph called 'dfx-test'

  4. Install The Graph's CLI on your terminal npm install -g @graphprotocol/graph-cli

  5. Clone this repo git clone https://github.com/dfx-finance/subgraph.git

  6. Install dependencies yarn install

  7. Go into the directory cd subgraph


Deploy

  1. Generate the code from the schema yarn codegen (This should be done every time the schema is changed)

  2. Copy the Deploy Key from https://thegraph.com/studio/ under 'dfx-test'

  3. In your command line, graph auth --studio

  4. Paste your Deploy Key when prompted

  5. Deploy to your instance yarn deploy-test:mainnet

  6. Set version to 'v0.0.1' and increment as you update the schema and source code.

  7. Go back to https://thegraph.com/studio/dfx-test and you can start querying in the Playground even before the subgraph has synced to 100%

  8. Run this query to get the latest trades ordered from newest to oldest


Deploy Legacy Explorer (Hosted)

The legacy explorer is the free public subgraph service provided by the graph. It can be seen as the centralized production environment.

  1. yarn prepare:mainnet

  2. yarn codegen

  3. yarn deploy-prod:mainnet


Documentation


Debugging

Common issues:

One of the most common issues when changing the schema is all specified fields except for the id must be initialized or the subgraph will fail to index.

For example given this schema for the parent factory contract

type DFXFactory @entity {
  # factory address
  id: ID!

  # pair info
  pairCount: Int!

  # total volume
  totalVolumeUSD: BigDecimal!

  # total liquidity
  totalLiquidityUSD: BigDecimal!
  # transactions
  # txCount: BigInt!
}

The subsequent mapping definition must have all fields present and defined.

factory = new DFXFactory(FACTORY_ADDRESS)
factory.pairCount = 0
factory.totalVolumeUSD = ZERO_BD
factory.totalLiquidityUSD = ZERO_BD

Configuration constants must be lowercase (Bad Example)

0x84Bf8151394dcF32146965753B28760550f3D7A8

(Good Example)

0x84bf8151394dcf32146965753b28760550f3d7a8

Switching from Ethereum to Polygon and vice versa requires a small change in subgraph\src\helpers.ts.

In fetchRewardsForDuration() there is a function that makes calls to the staking contracts contract.getRewardForDuration() in Ethereum it is just 1 BigDecimal but Polygon the number is inside an array so upon switching between the two there needs to be a small change of contract.getRewardForDuration()[0].


Logging

To help with debugging the The Graph has provided a logging object within the graph-ts module.

import { log } from "@graphprotocol/graph-ts";

This can be used almost anywhere in your mapping code the provide insight on values that are being defined on your schema. There are four different types of logs that can be defined error, warn, info, debug They all follow the format of string message followed by and string array filled with your variables. They will show up after the subgraph is deployed. For example

log.debug("The amount of pairs currently in dfx is {}", [factory.pairCount.toString()])

Note: Addresses and transaction hashes must be converted to Hexstrings in order to show up properly in the logging.

Full documentation on how to use GraphQL queries in The Graph playground can be found .

🕸️
📖
here
DFX factory
https://github.com/dfx-finance/subgraph
USDC/XSGD
USDC/EURS
USDC/CADC
USDC/NZDS
USDC/TRYB
USDC/XIDR
USDC/XSGD
USDC/EURS
USDC/CADC
USDC/TRYB