Skip to content

groLabs/gro-subgraph-avalanche

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 in Avalanche mainnet to provide personal stats on:

  • Deposits, withdrawals, transfers and approvals of groDAI, groUSDC and groUSDT tokens at transaction level

  • Net amounts, current balance and net returns at aggregated level

Active deployments

Hosted service:

(1) to be decommissioned in 2023 Q1

Decentralised network:

  • Ethereum Prod [Production → full mainnet data]

  • Ethereum Test [Development → sample mainnet data only for Gro devs]

Setup

  1. Clone the Gro subgraph
git clone https://github.com/groLabs/gro-subgraph-avalanche.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 Ethereum subgraph is located in another repository as it contains different products and smart contracts.

Key Entities

User

It is the user wallet address that connects with most of the other entities such as totals, transfers or approvals.

Totals

Aggregated net balance as the basis to calculate the user’s current balance and net returns for groDAI, groUSDC and groUSDT (versions 1.0 and 1.7).

Price

Latest token prices for groDAI, groUSDC and groUSDT (versions 1.0 and 1.7).

TransferTx

Contains the following transactions depending on field type:

Type

Description

Contract

Event

deposit

groDAI, groUSDC & groUSDT deposits into Labs

Labs 1.0 and 1.7

LogDeposit

withdrawal

groDAI, groUSDC & groUSDT withdrawals from Labs

Labs 1.0 and 1.7

LogWithdrawal

transfer_in

groDAI, groUSDC & groUSDT transfers received

Labs 1.0 and 1.7

Transfer

transfer_out

groDAI, groUSDC & groUSDT transfers sent

Labs 1.0 and 1.7

Transfer

ApprovalTx

Contains approval transactions for groDAI, groUSDC and groUSDT in Labs 1.0 and 1.7.

Queries

  • Personal stats
{
  prices {
    groDAI_e_v1_0
    groUSDC_e_v1_0
    groUSDT_e_v1_0
    groDAI_e_v1_7
    groUSDC_e_v1_7
    groUSDT_e_v1_7
  }
  users(where: {id: "0x2ce1a66f22a2dc6e410d9021d57aeb8d13d6bfef"}) {
    address: id
    totals {
      value_added_groDAI_e_v1_0
      value_added_groUSDC_e_v1_0
      value_added_groUSDT_e_v1_0
      value_added_groDAI_e_v1_7
      value_added_groUSDC_e_v1_7
      value_added_groUSDT_e_v1_7
      value_added_total
      value_removed_groDAI_e_v1_0
      value_removed_groUSDC_e_v1_0
      value_removed_groUSDT_e_v1_0
      value_removed_groDAI_e_v1_7
      value_removed_groUSDC_e_v1_7
      value_removed_groUSDT_e_v1_7
      value_removed_total
      net_value_groDAI_e_v1_0
      net_value_groUSDC_e_v1_0
      net_value_groUSDT_e_v1_0
      net_value_groDAI_e_v1_7
      net_value_groUSDC_e_v1_7
      net_value_groUSDT_e_v1_7
      net_value_total
      net_amount_groDAI_e_v1_0
      net_amount_groUSDC_e_v1_0
      net_amount_groUSDT_e_v1_0
      net_amount_groDAI_e_v1_7
      net_amount_groUSDC_e_v1_7
      net_amount_groUSDT_e_v1_7
      # // The following fields must be calculated on the front-end side:
      # current_balance_groDAI_e_v1_0 = totals.net_amount_groDAI_e_v1_0 * prices.groDAI_e_v1_0
      # current_balance_groUSDC_e_v1_0 = totals.net_amount_groUSDC_e_v1_0 * prices.groUSDC_e_v1_0
      # current_balance_groUSDT_e_v1_0 = totals.net_amount_groUSDT_e_v1_0 * prices.groUSDT_e_v1_0
      # current_balance_groDAI_e_v1_7 = totals.net_amount_groDAI_e_v1_7 * prices.groDAI_e_v1_7
      # current_balance_groUSDC_e_v1_7 = totals.net_amount_groUSDC_e_v1_7 * prices.groUSDC_e_v1_7
      # current_balance_groUSDT_e_v1_7 = totals.net_amount_groUSDT_e_v1_7 * prices.groUSDT_e_v1_7
      # current_balance_total = current_balance_groDAI_e_v1_0 + current_balance_groUSDC_e_v1_0 
      #                       + current_balance_groUSDT_e_v1_0 + current_balance_groDAI_e_v1_7 
      #                       + current_balance_groUSDC_e_v1_7 + current_balance_groUSDT_e_v1_7
      # net_returns_groDAI_e_v1_0 = totals.current_balance_groDAI_e_v1_0 * totals.net_value_groDAI_e_v1_0
      # net_returns_groUSDC_e_v1_0 = totals.current_balance_groUSDC_e_v1_0 * totals.net_value_groUSDC_e_v1_0
      # net_returns_groUSDT_e_v1_0 = totals.current_balance_groUSDT_e_v1_0 * totals.net_value_groUSDT_e_v1_0
      # net_returns_groDAI_e_v1_7 = totals.current_balance_groDAI_e_v1_7 * totals.net_value_groDAI_e_v1_7
      # net_returns_groUSDC_e_v1_7 = totals.current_balance_groUSDC_e_v1_7 * totals.net_value_groUSDC_e_v1_7
      # net_returns_groUSDT_e_v1_7 = totals.current_balance_groUSDT_e_v1_7 * totals.net_value_groUSDT_e_v1_7
      # net_returns_total = totals.current_balance_total - net_value_total
    }
    core_deposits: transfers(where: {type: deposit}) {
      block
      timestamp
      hash
      token
      coinAmount
      usdAmount
    }
    core_withdrawals: transfers(where: {type: withdrawal}) {
      block
      timestamp
      hash
      token
      coinAmount
      usdAmount
    }
    core_transfers_in: transfers(where: {type: transfer_in}) {
      block
      timestamp
      hash
      token
      coinAmount
      usdAmount
    }
    core_transfers_out: transfers(where: {type: transfer_out}) {
      block
      timestamp
      hash
      token
      coinAmount
      usdAmount
    }
    core_approvals: approvals(where: {type: approval}) {
      block
      timestamp
      hash
      token
      spenderAddress
      coinAmount
      usdAmount
    }
  }
}

Enjoy it! 😁