A Graph Protocol subgraph for indexing and querying blockchain events from the Zield Protocol smart contracts on Base Sepolia.
This subgraph indexes events from the Zield Protocol's CDP (Collateralized Debt Position) system, tracking user activities including:
- Collateral deposits and withdrawals
- Borrowing and repayment operations
- Liquidation events
- Protocol adapter registration
- Token whitelisting
Address: 0x7928f54d9B05d50F5B0e7faC884A62e9302abe95
Tracks the main CDP operations:
- CollateralDeposited: User deposits yield-bearing tokens
- CollateralWithdrawn: User withdraws collateral
- Borrowed: User borrows zUSD against collateral
- Repaid: User repays borrowed zUSD
- Liquidated: Liquidation of undercollateralized positions
- ZieldTokenCreated: New Zield token wrapper creation
Address: 0x6cCF953aA3Cd41BE2013D86797671c21D1BF34AF
Tracks protocol configuration:
- AdapterRegistered: Protocol adapter added (Lido, Aave, Compound)
- AdapterRemoved: Protocol adapter removed
- TokenWhitelisted: Yield token approved for use
- TokenRemoved: Token removed from whitelist
type CollateralDeposited @entity(immutable: true) {
  id: Bytes!
  user: Bytes!           # User address
  yieldToken: Bytes!     # Token address (wstETH, aUSDC, cDAI)
  amount: BigInt!        # Deposit amount
  protocol: String!      # Protocol name (Lido, Aave, Compound)
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}type Borrowed @entity(immutable: true) {
  id: Bytes!
  user: Bytes!          # Borrower address
  amount: BigInt!       # Amount borrowed in zUSD
  totalDebt: BigInt!    # User's total debt after borrowing
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}type Repaid @entity(immutable: true) {
  id: Bytes!
  user: Bytes!
  amount: BigInt!           # Amount repaid
  remainingDebt: BigInt!    # Debt after repayment
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}type Liquidated @entity(immutable: true) {
  id: Bytes!
  user: Bytes!              # Liquidated user
  liquidator: Bytes!        # Liquidator address
  debtCovered: BigInt!      # Debt covered in liquidation
  collateralSeized: BigInt! # Collateral taken by liquidator
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}type TokenWhitelisted @entity(immutable: true) {
  id: Bytes!
  token: Bytes!         # Token address
  protocolName: String! # Associated protocol
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}type AdapterRegistered @entity(immutable: true) {
  id: Bytes!
  protocolName: String! # Protocol name
  adapter: Bytes!       # Adapter contract address
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}- Node.js 16+
- Yarn package manager
- Graph CLI
- Goldsky account (for deployment)
yarn installUpdate networks.json with your contract addresses:
{
  "base-sepolia": {
    "MultiProtocolCDP": {
      "address": "0x7928f54d9B05d50F5B0e7faC884A62e9302abe95",
      "startBlock": 32708885
    },
    "VaultRegistry": {
      "address": "0x6cCF953aA3Cd41BE2013D86797671c21D1BF34AF"
    }
  }
}Generate TypeScript types from GraphQL schema and ABIs:
yarn codegenCompile the subgraph:
yarn buildRun unit tests with Matchstick:
yarn testThe subgraph is deployed to Goldsky for production use.
yarn goldsky-initThis will:
- Login to Goldsky
- Generate code
- Build the subgraph
- Deploy to Goldsky
yarn goldskyThis will:
- Login to Goldsky
- Remove existing deployment
- Regenerate and rebuild
- Deploy new version
yarn create-localyarn deploy-localRequires a local Graph node running at:
- Graph Node: http://localhost:8020/
- IPFS: http://localhost:5001
yarn remove-localDeploy to The Graph's hosted service:
yarn deployhttps://api.goldsky.com/api/public/project_cmh2orech3c0v01q1ay82bvjm/subgraphs/zield/0.0.1/gn
query RecentDeposits {
  collateralDepositeds(
    first: 10
    orderBy: blockTimestamp
    orderDirection: desc
  ) {
    id
    user
    yieldToken
    amount
    protocol
    blockTimestamp
    transactionHash
  }
}query UserBorrows($user: Bytes!) {
  borroweds(
    where: { user: $user }
    orderBy: blockTimestamp
    orderDirection: desc
  ) {
    id
    amount
    totalDebt
    blockTimestamp
    transactionHash
  }
}query UserActivity($user: Bytes!) {
  collateralDepositeds(where: { user: $user }) {
    id
    yieldToken
    amount
    protocol
    blockTimestamp
  }
  borroweds(where: { user: $user }) {
    id
    amount
    totalDebt
    blockTimestamp
  }
  repaids(where: { user: $user }) {
    id
    amount
    remainingDebt
    blockTimestamp
  }
  collateralWithdrawns(where: { user: $user }) {
    id
    yieldToken
    amount
    blockTimestamp
  }
}query Liquidations {
  liquidateds(
    first: 20
    orderBy: blockTimestamp
    orderDirection: desc
  ) {
    id
    user
    liquidator
    debtCovered
    collateralSeized
    blockTimestamp
    transactionHash
  }
}query WhitelistedTokens {
  tokenWhitelisteds {
    id
    token
    protocolName
    blockTimestamp
  }
}query Adapters {
  adapterRegistereds {
    id
    protocolName
    adapter
    blockTimestamp
  }
}/
βββ abis/                        # Contract ABIs
β   βββ MultiProtocolCDP.json
β   βββ VaultRegistry.json
βββ src/                         # Event handlers
β   βββ multi-protocol-cdp.ts  # CDP event handlers
β   βββ vault-registry.ts       # Registry event handlers
βββ generated/                   # Auto-generated code
βββ build/                       # Compiled subgraph
βββ tests/                       # Matchstick tests
βββ schema.graphql              # GraphQL schema definition
βββ subgraph.yaml               # Subgraph manifest
βββ networks.json               # Network configurations
βββ docker-compose.yml          # Local Graph node setup
βββ package.json
All event handlers follow the pattern:
- Create entity from event
- Map event parameters to entity fields
- Add block metadata (number, timestamp, hash)
- Save entity to The Graph
Example:
export function handleBorrowed(event: BorrowedEvent): void {
  let entity = new Borrowed(
    event.transaction.hash.concatI32(event.logIndex.toI32())
  )
  entity.user = event.params.user
  entity.amount = event.params.amount
  entity.totalDebt = event.params.totalDebt
  entity.blockNumber = event.block.number
  entity.blockTimestamp = event.block.timestamp
  entity.transactionHash = event.transaction.hash
  entity.save()
}- @graphprotocol/graph-cli: 0.97.1 - Graph CLI tools
- @graphprotocol/graph-ts: 0.37.0 - AssemblyScript runtime
- matchstick-as: 0.6.0 - Unit testing framework
- Chain: Base Sepolia (testnet)
- Network ID: base-sepolia
- Start Block: 32708885
Query subgraph health and sync status via The Graph Explorer or Goldsky dashboard.
# Clean and regenerate
rm -rf generated build
yarn codegen- Verify contract addresses in networks.json
- Check start block number
- Ensure ABIs are up to date
- Confirm Goldsky authentication
- Check entity names match schema
- Verify field types
- Ensure proper filtering syntax
UNLICENSED - Hackathon Project
This is a hackathon project for the Zield Protocol. For questions or contributions, contact the development team.
Built for Base Sepolia testnet | Powered by The Graph & Goldsky