BlockChain區塊鏈
  • 本書簡介
  • 區塊鏈運作原理
  • Bitcoin介紹
    • 簡介
    • Bitcoin其他知識
  • Bitcoin原理與實作
  • BitcoinJS
    • BTC 地址格式種類
    • 從 Mnemonic 轉為地址
  • Serverless 架構實作
  • Docker常用指令
  • ethereum初探
    • ethereum歷史
    • EVM
  • ethereum PoS 節點架設
  • ethereum(Docker)
  • ethereum(Geth)
    • Parity
  • ethereum(智能合約)
    • 合約測試 Unit Test
    • DAO
    • 可升級合約
    • 使用合約進行 multiswap
    • 合約安全
    • 開發工具
    • Hardhat 教學
      • Hardhat 寫測試
    • ERC-721 範例
      • 白名單機制
    • OpenZeppelin 合約 library
    • Truffle
    • 合約部屬
    • solidity 教學
  • ethereum(Dapp)
    • 相關 SDK
    • Multicall
    • Ethers.js 使用
    • Remix IDE
    • web3.js 使用
    • 在網頁上使用 web3 並操作區塊鏈
      • solidity筆記
  • Hyperledger Fabric
  • blockchainDB
  • 挖礦程式使用教學
    • 門羅幣/Monero (XMR)
  • Bitfinex API 使用
  • FTX API
  • CCXT 通用交易所 API
  • Solana 教學
  • Ethereum BigQuery
  • The Graph
    • yaml 定義
    • mapping 語法
    • Schema 定義
    • Query 範例
    • Unit test
  • DeFi 筆記
    • MEV 相關
    • Dex 聚合
    • Yearn
    • Curve
    • Uniswap
      • Swap 互動
    • AAVE、Compound
      • Compound 原理
      • AAVE 合約開發
Powered by GitBook
On this page
  • AAVE APY
  • Compound APY
  • Uniswap
  • 其他範例
  • Filter 欄位返回

Was this helpful?

  1. The Graph

Query 範例

範例

PreviousSchema 定義NextUnit test

Last updated 2 years ago

Was this helpful?

AAVE APY

Market Data

{
  reserves {
    name
    symbol
    totalLiquidity
    totalDeposits
	price {
		oracle {
			usdPriceEth
			}
		        priceInEth
		}
		aToken {
			id
			underlyingAssetAddress
		}
	}
}

liquidity 即為 deposit rate 而 stableBorrowRate, variableBorrowRate 為 borrow rate

Compound APY

{
  markets {
    borrowRate
    supplyRate
    symbol
    id
    totalBorrows
    totalSupply
    underlyingAddress
    underlyingName
    underlyingPrice
    underlyingSymbol
    reserveFactor
    underlyingPriceUSD
  }
}

Uniswap

user swap history

{
  swaps(where: { from: "0x0Baf7b79F9174c0840aa93a93a2c2A81044A09a2" }) {
    transaction {
      id
      blockNumber
      timestamp
      swaps {
        from
        to
        amountUSD
        amount0In
        amount1In
        amount0Out
        amount1Out
        pair {
          token0 {
            symbol
            name
          }
          token1 {
            symbol
            name
          }
        }
      }
    }
  }
}

其他範例

可 import 以下 json 到 postman 測試

{"info":{"_postman_id":"326ee33e-0b9e-4c3a-9128-13486f4a4d95","name":"Subgraph Research For Assest Dashboard","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json"},"item":[{"name":"AAVE","item":[{"name":"Market Data","id":"0f66824a-21ed-40f1-80b5-695aedd00f62","request":{"method":"POST","header":[],"body":{"mode":"graphql","graphql":{"query":"{\n  reserves {\n    name\n\t\tsymbol\n    totalLiquidity\n    totalDeposits\n\t\tprice {\n\t\t\toracle {\n\t\t\t\tusdPriceEth\n\t\t\t\t}\n\t\t\t\tpriceInEth\n\t\t\t}\n\t\t\taToken {\n\t\t\t\tid\n\t\t\t\tunderlyingAssetAddress\n\t\t\t}\n\t\t}\n}","variables":""}},"url":"https://api.thegraph.com/subgraphs/name/aave/protocol-v2"},"response":[]},{"name":"User Deposit history","id":"11748ea0-b308-475a-b3e3-9f9be46ab7d2","request":{"method":"POST","header":[],"body":{"mode":"graphql","graphql":{"query":"{\n  user(id: \"0x4828d2f2836f02a480340707aaf7fa10c5b822bb\") {\n   depositHistory {\n    id\n    pool {\n      id\n    }\n    reserve {\n      name\n    }\n  }\n }\n}","variables":""}},"url":"https://api.thegraph.com/subgraphs/name/aave/protocol-v2"},"response":[]},{"name":"User aToken balance","id":"7516c72b-651b-4d63-af14-4259522a977d","request":{"method":"POST","header":[],"body":{"mode":"graphql","graphql":{"query":"{\n  user(id: \"0x4828d2f2836f02a480340707aaf7fa10c5b822bb\") {\n   reserves{\n    id\n    currentATokenBalance\n  }\n }\n}","variables":""}},"url":"https://api.thegraph.com/subgraphs/name/aave/protocol-v2"},"response":[]},{"name":"Deposit and borrow rate","id":"a9659538-9921-4675-8419-ec85ae1ff093","request":{"method":"POST","header":[],"body":{"mode":"graphql","graphql":{"query":"{\n  reserves {\n    name\n    underlyingAsset\n    \n    liquidityRate \n    stableBorrowRate\n    variableBorrowRate\n    \n    aEmissionPerSecond\n    vEmissionPerSecond\n    sEmissionPerSecond\n    \n    totalATokenSupply\n    totalCurrentVariableDebt\n  }\n}","variables":""}},"url":"https://api.thegraph.com/subgraphs/name/aave/protocol-v2"},"response":[]}],"id":"85b8d197-3eb9-45c3-b65b-23f469055af5"},{"name":"Compound","item":[{"name":"Market Data","id":"a4b93e06-2b4d-4f4c-8d92-2c402d9a78ae","request":{"method":"POST","header":[],"body":{"mode":"graphql","graphql":{"query":"{\n  markets(first: 100) {\n    borrowRate\n    cash\n    collateralFactor\n    exchangeRate\n    interestRateModelAddress\n    name\n    reserves\n    supplyRate\n    symbol\n    id\n    totalBorrows\n    totalSupply\n    underlyingAddress\n    underlyingName\n    underlyingPrice\n    underlyingSymbol\n    reserveFactor\n    underlyingPriceUSD\n  }\n}\n","variables":""}},"url":"https://api.thegraph.com/subgraphs/name/graphprotocol/compound-v2"},"response":[]},{"name":"User transaction history","id":"3f5147f8-cdfe-41d8-8539-b45e2700e81f","request":{"method":"POST","header":[],"body":{"mode":"graphql","graphql":{"query":"{\n  account(id: \"0x00000000af5a61acaf76190794e3fdf1289288a1\") {\n    tokens {\n      symbol\n      transactions {\n        tx_hash\n      }\n    }\n  }\n}\n","variables":""}},"url":"https://api.thegraph.com/subgraphs/name/graphprotocol/compound-v2"},"response":[]},{"name":"User cToken balance","id":"a671764d-a1d4-4738-9b7e-7644b69008b4","request":{"method":"POST","header":[],"body":{"mode":"graphql","graphql":{"query":"{\n  account(id: \"0x00000000af5a61acaf76190794e3fdf1289288a1\") {\n    id\n    tokens{\n      id\n      symbol\n      cTokenBalance\n    }\n  }\n}\n","variables":""}},"url":"https://api.thegraph.com/subgraphs/name/graphprotocol/compound-v2"},"response":[]},{"name":"Deposit and borrow rate","id":"bf25875e-079a-4912-915c-491e23e810da","request":{"method":"POST","header":[],"body":{"mode":"graphql","graphql":{"query":"{\n  markets {\n    borrowRate\n    supplyRate\n    symbol\n    id\n    totalBorrows\n    totalSupply\n    underlyingAddress\n    underlyingName\n    underlyingPrice\n    underlyingSymbol\n    reserveFactor\n    underlyingPriceUSD\n  }\n}","variables":""}},"url":"https://api.thegraph.com/subgraphs/name/graphprotocol/compound-v2"},"response":[]}],"id":"cb2388ab-84c9-41ba-8e17-02d2732d6196"}]}

Filter 欄位返回

query 時 filter 返回欄位用: <欄位名稱>_in

{
  pairs(where: {
    id_in: ["0x00645a275837d56a738d8988a41c0082b872add0", "0x11145a275837d56a738d8988a41c0082b872add0"],
  }) {
    id
    reserve0
    reserve1
    totalSupply
    token0 {
      symbol
    }
    token1 {
      symbol
    }
  }
}

https://github.com/Uniswap/v2-subgraph/
https://thegraph.com/hosted-service/subgraph/easonwang01/uniswap?selected=playground
https://thegraph.com/docs/en/developer/graphql-api/#filtering
APY and APRDevelopers
Yoga GraphiQL
Logo
Logo