Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy core subgraph #121

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions subgraphs/isolated-pools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"build:bsc": "graph build --ipfs https://api.thegraph.com/ipfs/ ",
"deploy:integration": "graph deploy venusprotocol/venus-isolated-pools --ipfs http://localhost:5001 --node http://127.0.0.1:8020/",
"deploy:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml && npx mustache config/docker.json src/constants/config-template > src/constants/config.ts && npx graph deploy venusprotocol/venus-isolated-pools --ipfs http://ipfs:5001 --node http://graph-node:8020/ --version-label ci",
"deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-isolated-pools-chapel --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-isolated-pools --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-isolated-pools-chapel --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-isolated-pools --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"prepare:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml && npx mustache config/docker.json src/constants/config-template > src/constants/config.ts",
"prepare:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts",
"prepare:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts",
Expand Down
5 changes: 3 additions & 2 deletions subgraphs/venus/config/bsc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"network": "bsc",
"address": "0xfd36e2c2a6789db23113685031d7f16329158384",
"startBlock": "2470000"
"comptrollerAddress": "0xfd36e2c2a6789db23113685031d7f16329158384",
"startBlock": "2470000",
"vBnbAddress": "0xA07c5b74C9B40447a954e1466938b865b6BBea36"
}
5 changes: 3 additions & 2 deletions subgraphs/venus/config/chapel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"network": "bsc-testnet",
"address": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D",
"startBlock": "2470000"
"comptrollerAddress": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D",
"startBlock": "2470000",
"vBnbAddress": "0x2E7222e51c0f6e98610A1543Aa3836E092CDe62c"
}
5 changes: 3 additions & 2 deletions subgraphs/venus/config/docker.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"network": "bsc-testnet",
"address": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D",
"startBlock": "0"
"comptrollerAddress": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D",
"startBlock": "0",
"vBnbAddress": "0xA07c5b74C9B40447a954e1466938b865b6BBea36"
}
8 changes: 4 additions & 4 deletions subgraphs/venus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"build:bsc": "graph build --ipfs https://api.thegraph.com/ipfs/ ",
"deploy:integration": "graph deploy venusprotocol/venus-subgraph --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020/",
"deploy:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml && npx mustache config/docker.json src/constants/config-template > src/constants/config.ts && npx graph deploy venusprotocol/venus-subgraph --ipfs http://ipfs:5001 --node http://graph-node:8020/ --version-label ci",
"deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-subgraph -chapel --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-subgraph e --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"prepare:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml",
"prepare:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml",
"deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-subgraph-chapel --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"prepare:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml && npx mustache config/docker.json src/constants/config-template > src/constants/config.ts",
"prepare:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts",
"prepare:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts",
"test": "graph test",
"test:integration": "true"
Expand Down
30 changes: 14 additions & 16 deletions subgraphs/venus/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ interface VTokenTransfer {
"Transaction hash concatenated with log index"
id: ID!
"vTokens transferred"
amount: BigDecimal!
amountMantissa: BigInt!
"Account that received tokens"
to: Bytes!
"Account that sent tokens"
Expand All @@ -165,8 +165,6 @@ interface VTokenTransfer {
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the vToken transferred"
vTokenSymbol: String!
}

"""
Expand All @@ -186,8 +184,8 @@ type TransferEvent implements VTokenTransfer @entity {
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the vToken transferred"
vTokenSymbol: String!
"Address of the vToken transferred"
vTokenAddress: Bytes!
}

"""
Expand All @@ -207,7 +205,7 @@ type MintEvent implements VTokenTransfer @entity {
blockNumber: Int!
"Block time"
blockTime: Int!
"Address of the vToken transferred"
"Address of the vToken minted"
vTokenAddress: Bytes!
"Underlying token amount transferred"
underlyingAmountMantissa: BigInt!
Expand Down Expand Up @@ -253,10 +251,10 @@ type LiquidationEvent implements VTokenTransfer @entity {
blockNumber: Int!
"Block time"
blockTime: Int!
"vToken that was sezied as collateral"
vTokenSymbol: String!
"Symbol of the underlying asset repaid through liquidation"
underlyingSymbol: String!
"Address of the vToken that was seized as collateral"
vTokenCollateralAddress: Bytes!
"Address of the underlying asset repaid through liquidation"
underlyingRepaidAddress: Bytes!
"Underlying vToken amount that was repaid by liquidator"
underlyingRepayAmountMantissa: BigInt!
}
Expand All @@ -278,8 +276,8 @@ interface UnderlyingTransfer {
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the borrowed underlying asset"
underlyingSymbol: String!
"Address of the underlying token that was seized as transferred"
underlyingAddress: Bytes!
}

"""
Expand All @@ -298,8 +296,8 @@ type BorrowEvent implements UnderlyingTransfer @entity {
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the borrowed underlying asset"
underlyingSymbol: String!
"Address of the underlying token that was borrowed"
underlyingAddress: Bytes!
}

"""
Expand All @@ -319,8 +317,8 @@ type RepayEvent implements UnderlyingTransfer @entity {
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the borrowed underlying asset"
underlyingSymbol: String!
"Address of the underlying token that was repaid"
underlyingAddress: Bytes!
"Payer of the borrow funds"
payer: Bytes!
}
12 changes: 7 additions & 5 deletions subgraphs/venus/src/constants/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Address } from '@graphprotocol/graph-ts';

export const vBnbAddress = Address.fromString('0xA07c5b74C9B40447a954e1466938b865b6BBea36');
export const interestRateModelAddress = Address.fromString(
'0x594942C0e62eC577889777424CD367545C796A74',
);
export const comptrollerAddress = Address.fromString('0xfd36e2c2a6789db23113685031d7f16329158384');
import {
comptrollerAddress as comptrollerAddressString,
vBnbAddress as vBnbAddressString,
} from './config';

export const vBnbAddress = Address.fromString(vBnbAddressString);
export const comptrollerAddress = Address.fromString(comptrollerAddressString);
export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000');
4 changes: 4 additions & 0 deletions subgraphs/venus/src/constants/config-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Use yarn prepare commands to generate config typescript file per env

export const vBnbAddress = '{{ vBnbAddress }}';
export const comptrollerAddress = '{{ comptrollerAddress }}';
36 changes: 17 additions & 19 deletions subgraphs/venus/src/mappings/comptroller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable prefer-const */
// to satisfy AS compiler
import { BigInt, log } from '@graphprotocol/graph-ts';
import { log } from '@graphprotocol/graph-ts';

import {
DistributedSupplierVenus,
Expand All @@ -19,15 +19,15 @@ import { getOrCreateComptroller } from '../operations/getOrCreate';
import { updateCommonVTokenStats } from '../operations/update';
import { ensureComptrollerSynced } from '../utilities';

export const handleMarketListed = (event: MarketListed): void => {
export function handleMarketListed(event: MarketListed): void {
// Dynamically index all new listed tokens
VToken.create(event.params.vToken);
// Create the market for this token, since it's now been listed.
let market = createMarket(event.params.vToken.toHexString());
market.save();
};
}

export const handleMarketEntered = (event: MarketEntered): void => {
export function handleMarketEntered(event: MarketEntered): void {
let market = Market.load(event.params.vToken.toHexString());
// Null check needed to avoid crashing on a new market added. Ideally when dynamic data
// sources can source from the contract creation block and not the time the
Expand Down Expand Up @@ -60,9 +60,9 @@ export const handleMarketEntered = (event: MarketEntered): void => {
);
vTokenStats.enteredMarket = true;
vTokenStats.save();
};
}

export const handleMarketExited = (event: MarketExited): void => {
export function handleMarketExited(event: MarketExited): void {
let market = Market.load(event.params.vToken.toHexString());
// Null check needed to avoid crashing on a new market added. Ideally when dynamic data
// sources can source from the contract creation block and not the time the
Expand Down Expand Up @@ -95,15 +95,15 @@ export const handleMarketExited = (event: MarketExited): void => {
);
vTokenStats.enteredMarket = false;
vTokenStats.save();
};
}

export const handleNewCloseFactor = (event: NewCloseFactor): void => {
export function handleNewCloseFactor(event: NewCloseFactor): void {
const comptroller = getOrCreateComptroller();
comptroller.closeFactor = event.params.newCloseFactorMantissa;
comptroller.save();
};
}

export const handleNewCollateralFactor = (event: NewCollateralFactor): void => {
export function handleNewCollateralFactor(event: NewCollateralFactor): void {
let market = Market.load(event.params.vToken.toHexString());
// Null check needed to avoid crashing on a new market added. Ideally when dynamic data
// sources can source from the contract creation block and not the time the
Expand All @@ -112,30 +112,28 @@ export const handleNewCollateralFactor = (event: NewCollateralFactor): void => {
market.collateralFactorMantissa = event.params.newCollateralFactorMantissa;
market.save();
}
};
}

// This should be the first event acccording to bscscan but it isn't.... price oracle is. weird
export const handleNewLiquidationIncentive = (event: NewLiquidationIncentive): void => {
export function handleNewLiquidationIncentive(event: NewLiquidationIncentive): void {
const comptroller = getOrCreateComptroller();
comptroller.liquidationIncentive = event.params.newLiquidationIncentiveMantissa;
comptroller.save();
};
}

export const handleNewPriceOracle = (event: NewPriceOracle): void => {
export function handleNewPriceOracle(event: NewPriceOracle): void {
const comptroller = getOrCreateComptroller();
comptroller.priceOracle = event.params.newPriceOracle;
comptroller.save();
};
}

// Also handles DistributedBorrowerVenus with same signature
export function handleXvsDistributed(event: DistributedSupplierVenus): void {
let vTokenAddress = event.params.vToken.toHex();
let venusDelta = event.params.venusDelta.toHex();
const venusDelta = event.params.venusDelta;
let market = Market.load(vTokenAddress);
if (market == null) {
market = createMarket(vTokenAddress);
}
market.totalXvsDistributedMantissa = market.totalXvsDistributedMantissa.plus(
BigInt.fromString(venusDelta),
);
market.totalXvsDistributedMantissa = market.totalXvsDistributedMantissa.plus(venusDelta);
}
Loading
Loading