Skip to content

groLabs/gro-subgraph-mainnet

Repository files navigation

Gro Subgraph

Gro Protocol is a DeFi yield aggregator that makes it easy to earn stablecoin yields with tranching & automation.

This subgraph dynamically tracks the interaction of users with Gro contracts together with Convex strategy contracts in Ethereum mainnet to provide insightful data on personal and global stats:

  • Deposits, withdrawals, transfers & approvals of GVT, PWRD and GRO tokens

  • Deposits, withdrawals, claims & swaps from staking contracts

  • Airdrop claims

  • Aggregated net amounts, current balance and net returns

  • Global staking pools & Convex strategies data

This info can be also used to calculate KPIs such as TVL, APYs or protocol exposure to stablecoins.

Active deployments

Hosted service:

(1) to be decommissioned during 2023

Decentralised network:

  • Ethereum Prod [Production → full mainnet data]

  • Ethereum Test [Development → mainnet test data for devs (currently not signaled)]

Setup

  1. Clone the Gro subgraph
git clone https://github.com/groLabs/gro-subgraph-mainnet.git
  1. Install dependencies
yarn install
  1. Run any of the below commands and scripts to generate and deploy subgraphs in TheGraph platform:
# Ethereum Prod - hosted service
yarn eth-prod-hosted 
# Ethereum Test - hosted service
yarn eth-test-hosted
# Avalanche Prod - hosted service
yarn avax-prod-hosted
# Avalanche Test - hosted service
yarn avax-test-hosted
# Ethereum Prod - decentralised network
yarn eth-prod-studio
# Ethereum Test - decentralised network
yarn eth-test-studio

The Avalanche subgraph is located in another repository as it contains a different product (Labs) and smart contracts.

As of 2023, the hosted service does not allow to create new subgraphs and the platform will be decommissioned soon.

Key Entities

MasterData: General info regarding the blockchain network, utilisation ratios or Gro per block distribution.

CoreData: Total supply for GRO, GVT, PWRD and LP tokens

Airdrop: Airdrop amounts allocated with its merkle root

User: User wallet address that links with most of the other entities such as totals, transfers, claims or approvals.

Totals: Aggregated data as the basis to calculate the user’s current balance and net returns for GVT and PWRD (excluding GRO)

Price: Latest token prices for GVT, GRO, 3CRV and the pool-related LP tokens (Curve Metapool PWRD3CRV, Uniswap GVT-GRO, Uniswap GRO-USDC & Balancer GRO-WETH). PWRD is always set to 1.

Factor: GVT and PWRD factors. For PWRD, it is used to calculate the current balance and net returns.

Pool: Pool balance and rewards per User

PoolData: Total supply & reserves for non single-sided pools (Uniswap, Curve & Balancer)

PoolSwap: Swaps from pool contracts. For Balancer, virtual price is retrieved in a regular basis instead of retrieving swaps (since Balancer vault is shared by other protocols and retrieving such a huge amount of events would impact subgraph performance)

GVault: 3CRV vault hosting all Convex strategies

GVaultStrategy: Convex strategies generating yields

GVaultHarvest: Harvests triggered from GVault over the strategies

VestingBonus: Vesting rewards per user

VestingAirdrop: Claimed PWRD amount from UST vesting airdrop per user

TransferTx: Contains the following transactions depending on field type:

Type

Description

Contract

Event

core_deposit

GVT & PWRD deposits into the protocol

Deposit handler + GRouter

LogNewDeposit

core_withdrawal

GVT & PWRD withdrawals from the protocol

Withdraw handler + GRouter

LogNewWithdrawal

staker_deposit

Deposits into staking contracts (1)

Staker

LogDeposit

staker_withdrawal

Withdrawals from staking contracts (1)

Staker

LogWithdraw

transfer_in

GVT, PWRD & GRO transfers received

(excluding from Staker contract)

Gro, Gvt, Pwrd

Transfer

transfer_out

GVT, PWRD & GRO transfers sent

(excluding to Staker contract)

Gro, Gvt, Pwrd

Transfer

claim

Claim GRO rewards

Stakers

LogClaim

multiclaim

Multi claim GRO rewards

Stakers

LogMultiClaim

(1) Tokens will depend on the pool

ApprovalTx: Contains approval transactions for GVT, PWRD & GRO tokens

StakerClaimTx: Contains GRO claims from staking contracts where poolId indicates which pool/s are the rewards coming from:

Pool ID

Tokens allocation

Description

0

100% GRO

Single Staking GRO

1

50 %GRO, 50% GVT

Uniswap V2 GRO - GVT

2

50% GRO, 50% USDC

Uniswap V2 GRO - USDC

3

100% GVT

Single Staking GVT

4

PWRD, USDC, USDT, DAI

Curve metapool PWRD

5

80% GRO, 20% WETH

Balancer V2 GRO - WETH

6

100% PWRD

Single Staking PWRD

-1

N/A

Missing pool

AirdropClaimTx: Airdrop claimed amounts

Queries

Following are two GraphQL examples to retrieve user and global data:

  • Personal stats
{
  users(where: {id: "0x......"}) {
    address: id
    totals {
      amount_added_gvt: value_added_gvt
      amount_added_pwrd: value_added_pwrd
      amount_added_total: value_added_total
      amount_removed_gvt: value_removed_gvt
      amount_removed_pwrd: value_removed_pwrd
      amount_removed_total: value_removed_total
      net_amount_gvt: net_value_gvt
      net_amount_pwrd: net_value_pwrd
      net_amount_total: net_value_total
    }
    airdrop_claims {
      id
      tranche_id
      contract_address
    }
    core_deposits: transfers(where: {type: core_deposit}) {
      block_number
      block_timestamp
      hash
      token
      coin_amount
      usd_amount
      factor
      pool_id
    }
    core_withdrawals: transfers(where: {type: core_withdrawal}) {
      block_number
      block_timestamp
      hash
      token
      coin_amount
      usd_amount
      factor
    }
    core_transfers_in: transfers(where: {type: transfer_in}) {
      block_number
      block_timestamp
      hash
      token
      coin_amount
      usd_amount
      factor
    }
    core_transfers_out: transfers(where: {type: transfer_out}) {
      block_number
      block_timestamp
      hash
      token
      coin_amount
      usd_amount
      factor
    }
    core_approvals: approvals(where: {type: approval}) {
      block_number
      block_timestamp
      hash
      token
      spender_address
      coin_amount
      usd_amount
    }
    staker_deposits: transfers(where: {type: staker_deposit}) {
      block_number
      block_timestamp
      hash
      pool_id
      coin_amount
    }
    staker_withdrawals: transfers(where: {type: staker_withdrawal}) {
      block_number
      block_timestamp
      hash
      pool_id
      coin_amount
    }
    staker_claims: claims {
      block_number
      block_timestamp
      hash
      vest
      pool_id
      amount
      type
    }
    pool_0: pools(where: {pool_id: 0}) {
      net_reward
      balance
    }
    pool_1: pools(where: {pool_id: 1}) {
      net_reward
      balance
    }
    pool_2: pools(where: {pool_id: 2}) {
      net_reward
      balance
    }
    pool_3: pools(where: {pool_id: 3}) {
      net_reward
      balance
    }
    pool_4: pools(where: {pool_id: 4}) {
      net_reward
      balance
    }
    pool_5: pools(where: {pool_id: 5}) {
      net_reward
      balance
    }
    pool_6: pools(where: {pool_id: 6}) {
      net_reward
      balance
    }
  }
}
  • Gro stats
{
  masterDatas {
    total_bonus
    total_bonus_in
    total_bonus_out
    total_locked_amount
    init_unlocked_percent
    global_start_time
  }
  gvaults {
    id
    locked_profit
    release_factor
    strategies {
      id
      metacoin
      strat_name
      strat_display_name
      strategy_debt
      vault_address {
        id
      }
      block_strategy_reported
      block_strategy_withdraw
    }
  }
  coreDatas {
    total_supply_gvt
    total_supply_pwrd_based
    total_supply_gro
    total_supply_curve_pwrd3crv
    total_supply_uniswap_gvt_gro
    total_supply_uniswap_gro_usdc
    total_supply_balancer_gro_weth
  }
  gvaultHarvests(orderBy: block_timestamp, orderDirection: desc, first:10) {
    strategy_address {
      id
    }
    gain
    loss
    debt_paid
    debt_added
    locked_profit
    block_timestamp
  }
  stakerDatas {
    id
    lp_supply
  }
  poolDatas {
    id
    reserve0
    reserve1
    total_supply
  }
  poolSwaps(orderBy: pool_id, orderDirection: desc, first:5, where: {pool_id: 2}) {
    pool_id
    virtual_price
    block_number
    block_timestamp
  }
}

For any further question, doubt, request or metaphysical reflection, please contact us at Discord

Enjoy it! 😁