Skip to content

bsamuels453/erc4626-subgraph

Repository files navigation

ERC-4626 Subgraph

This subgraph indexes the deposit & withdrawal activity of all ERC4626-compliant vaults.

It can be used to query an account's earnings, vault TVL statistics, and more.

Deployments

Ethereum Mainnet - Deployment - Explorer

Querying information about an account

For an account, show all outstanding vault positions

Try it

{
  accountPositions(
    where: {account: "0xaccountaddress", shares_gt: 0}
  ) {
    vault {
      id
      name
      underlying {
        name
      }
    }
    shares
  }
}

For a given account, show all deposit, withdraw, and transfer transactions the account has made with a vault.

Try it

{
  transferEvents(
    where: {receiver: "0xaccountaddress", vault: "0xvaultaddress"}
    orderBy: block
    orderDirection: desc
  ) {
    block
    sharesTransferred
  }
  depositEvents(
    where: {account: "0xaccountaddress", vault: "0xvaultaddress"}
    orderBy: block
    orderDirection: desc
  ) {
    id
    block
    assetsDeposited
    sharesMinted
  }
  withdrawEvents(
    where: {account: "0xaccountaddress", vault: "0xvaultaddress"}
    orderBy: block
    orderDirection: desc
  ) {
    id
    block
    assetsWithdrawn
    sharesRedeemed
  }
}

Show how much an account has earned by withdrawing from a specific vault.

Try it

{
  accountPositions(
    where: {account: "0xaccountaddress", vault: "0xvaultaddress"}
  ) {
    earnings(orderBy: block, orderDirection: asc) {
      block
      sharesRedeemed
      assetsWithdrawn
      profit
    }
  }
}

For a given transaction, display all of the ERC4626 deposit, withdraw, and transfer events.

Try it

{
  transaction(
    id: "0xtransactionid"
  ) {
    block
    timestamp
    depositEvents {
      logIndex
      account {
        id
      }
      vault {
        name
      }
      assetsDeposited
      sharesMinted
    }
    withdrawEvents {
      logIndex
      account {
        id
      }
      vault {
        name
      }
      assetsWithdrawn
      sharesRedeemed
    }
    transferEvents {
      logIndex
      sender {
        id
      }
      receiver {
        id
      }
      vault {
        name
      }
      sharesTransferred
    }
  }
}

Querying information about a vault

Show all of the vaults for a specific asset, ordered by TVL.

Try it

{
  erc4626Vaults(
    where:{underlying: "0xunderlyingTokenAddress"},
    orderBy: assetTvl
    orderDirection: desc
  ) {
    id
    name
    firstBlock
    assetTvl
  }
}

Developing

Installation

make install

Make changes to .env file as needed

Check out the makefile for build/deployment actions.

Notes for ERC4626 Vault Developers

Vault Detection

The subgraph detects new ERC4626 vaults by listening for ERC4626-specified deposit & withdraw events. Once detected, a series of contract calls are issued to verify whether the contract is ERC4626 compliant. The precise series of calls can be found in function doesContractImplement4626(address: Address).

Errata/Compatibility issues

Proxy upgraded vaults

If a protocol uses a proxy for its non-ERC4626 vaults, and later migrates to ERC4626, the subgraph will fail to account for user's deposits/withdraw activity before the migration. Users whose deposits occurred after the migration will not have any issues.

Protocols Impacted:

  • mStable

Implicitly immutable fields

Some fields defined by the ERC4626 spec are expected, but not required, to be immutable. The vault's name, asset, and decimals fall under this category. If a vault changes these fields as part of their normal operation, delayed initialziation, or proxy implementation, the subgraph will fail to index those vaults properly.

Protocols Impacted:

  • Sommelier

Disclaimers

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published