Skip to content

Commit

Permalink
feat: remove bifi from subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Dec 4, 2024
1 parent 230b35d commit c6bccb8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
2 changes: 2 additions & 0 deletions subgraphs/isolated-pools/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ const main = () => {
chapel: {
network: 'chapel',
poolRegistryAddress: chapelDeployments.addresses.PoolRegistry,
vBifiAddress: '0xEF949287834Be010C1A5EDd757c385FB9b644E4A',
startBlock: '30870000',
},
bsc: {
network: 'bsc',
poolRegistryAddress: bscMainnetDeployments.addresses.PoolRegistry,
vBifiAddress: '0xC718c51958d3fd44f5F9580c9fFAC2F89815C909',
startBlock: '29300000',
},
opbnbMainnet: {
Expand Down
7 changes: 6 additions & 1 deletion subgraphs/isolated-pools/src/constants/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Address } from '@graphprotocol/graph-ts';

import { poolRegistryAddress as poolRegistryAddressString } from './config';
import {
poolRegistryAddress as poolRegistryAddressString,
vBifiAddress as vBifiAddressString,
} from './config';

export const poolRegistryAddress = Address.fromString(poolRegistryAddressString);

export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000');

export const vBifiAddress = Address.fromString(vBifiAddressString);
2 changes: 2 additions & 0 deletions subgraphs/isolated-pools/src/constants/config-template
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Use yarn prepare commands to generate config typescript file per env

export const poolRegistryAddress = '{{ poolRegistryAddress }}';
// @ts-ignore When the template is created this will fallback to a null string
export const vBifiAddress = '{{ vBifiAddress }}' || '0x0000000000000000000000000000000000000000'
39 changes: 24 additions & 15 deletions subgraphs/isolated-pools/src/mappings/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ import Box from '../utilities/box';
export function handleMarketSupported(event: MarketSupported): void {
const comptroller = event.address;
const market = getOrCreateMarket(event.params.vToken, comptroller, event.block.number);
market.isListed = true;
market.collateralFactorMantissa = zeroBigInt32;
market.liquidationThresholdMantissa = zeroBigInt32;
market.save();
if (market) {
market.isListed = true;
market.collateralFactorMantissa = zeroBigInt32;
market.liquidationThresholdMantissa = zeroBigInt32;
market.save();
}
}

export function handleMarketUnlisted(event: MarketUnlisted): void {
Expand Down Expand Up @@ -90,17 +92,20 @@ export function handleNewCollateralFactor(event: NewCollateralFactor): void {
const vTokenAddress = event.params.vToken;
const newCollateralFactorMantissa = event.params.newCollateralFactorMantissa;
const market = getOrCreateMarket(vTokenAddress, poolAddress, event.block.number);
market.collateralFactorMantissa = newCollateralFactorMantissa;

market.save();
if (market) {
market.collateralFactorMantissa = newCollateralFactorMantissa;
market.save();
}
}

export function handleNewLiquidationThreshold(event: NewLiquidationThreshold): void {
const poolAddress = event.address;
const vTokenAddress = event.params.vToken;
const market = getOrCreateMarket(vTokenAddress, poolAddress, event.block.number);
market.liquidationThresholdMantissa = event.params.newLiquidationThresholdMantissa;
market.save();
if (market) {
market.liquidationThresholdMantissa = event.params.newLiquidationThresholdMantissa;
market.save();
}
}

export function handleNewLiquidationIncentive(event: NewLiquidationIncentive): void {
Expand Down Expand Up @@ -131,9 +136,11 @@ export function handleActionPausedMarket(event: ActionPausedMarket): void {
export function handleNewBorrowCap(event: NewBorrowCap): void {
const vTokenAddress = event.params.vToken;
const borrowCap = event.params.newBorrowCap;
const market = getMarket(vTokenAddress)!;
market.borrowCapMantissa = borrowCap;
market.save();
const market = getMarket(vTokenAddress);
if (market) {
market.borrowCapMantissa = borrowCap;
market.save();
}
}

export function handleNewMinLiquidatableCollateral(event: NewMinLiquidatableCollateral): void {
Expand All @@ -147,9 +154,11 @@ export function handleNewMinLiquidatableCollateral(event: NewMinLiquidatableColl
export function handleNewSupplyCap(event: NewSupplyCap): void {
const vTokenAddress = event.params.vToken;
const newSupplyCap = event.params.newSupplyCap;
const market = getMarket(vTokenAddress)!;
market.supplyCapMantissa = newSupplyCap;
market.save();
const market = getMarket(vTokenAddress);
if (market) {
market.supplyCapMantissa = newSupplyCap;
market.save();
}
}

export function handleNewRewardsDistributor(event: NewRewardsDistributor): void {
Expand Down
9 changes: 7 additions & 2 deletions subgraphs/isolated-pools/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Address, BigInt } from '@graphprotocol/graph-ts';

import { Comptroller as ComptrollerContract } from '../../generated/PoolRegistry/Comptroller';
import { PoolRegistry as PoolRegistryContract } from '../../generated/PoolRegistry/PoolRegistry';
import { VToken as VTokenDataSource } from '../../generated/templates';
import {
BadDebtIncreased,
Borrow,
Expand All @@ -25,7 +26,7 @@ import { RewardsDistributor as RewardDistributorContract } from '../../generated
import { BEP20 as BEP20Contract } from '../../generated/templates/VToken/BEP20';
import { VToken as VTokenContract } from '../../generated/templates/VToken/VToken';
import { BORROW, LIQUIDATE, MINT, REDEEM, REPAY, TRANSFER, zeroBigInt32 } from '../constants';
import { poolRegistryAddress } from '../constants/addresses';
import { poolRegistryAddress, vBifiAddress } from '../constants/addresses';
import { getTokenPriceInCents, valueOrNotAvailableIntIfReverted } from '../utilities';
import {
getAccountId,
Expand Down Expand Up @@ -84,7 +85,11 @@ export function createMarket(
vTokenAddress: Address,
comptroller: Address,
blockNumber: BigInt,
): Market {
): Market | null {
if (vTokenAddress.equals(vBifiAddress)) {
return null;
}
VTokenDataSource.create(vTokenAddress);
const vTokenContract = VTokenContract.bind(vTokenAddress);
const poolComptroller = Comptroller.bind(comptroller);
const underlyingAddress = vTokenContract.underlying();
Expand Down
4 changes: 1 addition & 3 deletions subgraphs/isolated-pools/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
RewardSpeed,
RewardsDistributor,
} from '../../generated/schema';
import { VToken as VTokenDataSource } from '../../generated/templates';
import { Comptroller } from '../../generated/templates/Pool/Comptroller';
import { RewardsDistributor as RewardDistributorContract } from '../../generated/templates/RewardsDistributor/RewardsDistributor';
import { zeroBigInt32 } from '../constants';
Expand All @@ -31,10 +30,9 @@ export const getOrCreateMarket = (
): Market => {
let market = getMarket(vTokenAddress);
if (!market) {
VTokenDataSource.create(vTokenAddress);
market = createMarket(vTokenAddress, comptrollerAddress, blockNumber);
}
return market;
return market as Market;
};

export const getOrCreatePool = (comptroller: Address): Pool => {
Expand Down

0 comments on commit c6bccb8

Please sign in to comment.