From c6bccb8c22a701a9a3ec3eb3efa6b3918cdce43f Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Wed, 27 Nov 2024 17:38:19 -0300 Subject: [PATCH] feat: remove bifi from subgraph --- subgraphs/isolated-pools/config/index.ts | 2 + .../isolated-pools/src/constants/addresses.ts | 7 +++- .../src/constants/config-template | 2 + subgraphs/isolated-pools/src/mappings/pool.ts | 39 ++++++++++++------- .../isolated-pools/src/operations/create.ts | 9 ++++- .../src/operations/getOrCreate.ts | 4 +- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/subgraphs/isolated-pools/config/index.ts b/subgraphs/isolated-pools/config/index.ts index 10474fc6..0971e098 100644 --- a/subgraphs/isolated-pools/config/index.ts +++ b/subgraphs/isolated-pools/config/index.ts @@ -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: { diff --git a/subgraphs/isolated-pools/src/constants/addresses.ts b/subgraphs/isolated-pools/src/constants/addresses.ts index 337ee1a0..9b2921fc 100644 --- a/subgraphs/isolated-pools/src/constants/addresses.ts +++ b/subgraphs/isolated-pools/src/constants/addresses.ts @@ -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); diff --git a/subgraphs/isolated-pools/src/constants/config-template b/subgraphs/isolated-pools/src/constants/config-template index bfbd86ff..c20a4da7 100644 --- a/subgraphs/isolated-pools/src/constants/config-template +++ b/subgraphs/isolated-pools/src/constants/config-template @@ -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' diff --git a/subgraphs/isolated-pools/src/mappings/pool.ts b/subgraphs/isolated-pools/src/mappings/pool.ts index 0d28fe74..77930400 100644 --- a/subgraphs/isolated-pools/src/mappings/pool.ts +++ b/subgraphs/isolated-pools/src/mappings/pool.ts @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/subgraphs/isolated-pools/src/operations/create.ts b/subgraphs/isolated-pools/src/operations/create.ts index 548cb01e..556c5d03 100644 --- a/subgraphs/isolated-pools/src/operations/create.ts +++ b/subgraphs/isolated-pools/src/operations/create.ts @@ -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, @@ -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, @@ -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(); diff --git a/subgraphs/isolated-pools/src/operations/getOrCreate.ts b/subgraphs/isolated-pools/src/operations/getOrCreate.ts index 4089c80f..d6610c13 100644 --- a/subgraphs/isolated-pools/src/operations/getOrCreate.ts +++ b/subgraphs/isolated-pools/src/operations/getOrCreate.ts @@ -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'; @@ -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 => {