From e4c2adf085eaa504cbf941ff26b87d5a8a015750 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Wed, 18 Dec 2024 10:14:27 -0300 Subject: [PATCH] fix: hardchade underlying weth token to avoid errors querying before existence --- .../isolated-pools/src/operations/create.ts | 8 ----- .../src/operations/getOrCreate.ts | 22 +++++++++++- subgraphs/venus/src/operations/getOrCreate.ts | 35 +++++++++++++------ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/subgraphs/isolated-pools/src/operations/create.ts b/subgraphs/isolated-pools/src/operations/create.ts index b35473ea..07eea54b 100644 --- a/subgraphs/isolated-pools/src/operations/create.ts +++ b/subgraphs/isolated-pools/src/operations/create.ts @@ -33,8 +33,6 @@ import { vagEURAddress, vankrBNBDeFiAddress, vankrBNBLiquidStakedBNBAddress, - vWETHLiquidStakedETHAddress, - vWETHCoreAddress, } from '../constants/addresses'; import { getOrCreateMarketReward, getOrCreateToken } from './getOrCreate'; import { getTokenPriceInCents, valueOrNotAvailableIntIfReverted } from '../utilities'; @@ -195,12 +193,6 @@ export function createMarket( market.symbol = 'vslisBNB_LiquidStakedBNB'; } - if (vTokenAddress.equals(vWETHLiquidStakedETHAddress) || vTokenAddress.equals(vWETHCoreAddress)) { - market.underlyingToken = getOrCreateToken( - Address.fromBytes(Bytes.fromHexString('0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9')), - ).id; - } - market.save(); return market; } diff --git a/subgraphs/isolated-pools/src/operations/getOrCreate.ts b/subgraphs/isolated-pools/src/operations/getOrCreate.ts index fb8eb455..5e141db1 100644 --- a/subgraphs/isolated-pools/src/operations/getOrCreate.ts +++ b/subgraphs/isolated-pools/src/operations/getOrCreate.ts @@ -1,4 +1,4 @@ -import { Address, BigInt } from '@graphprotocol/graph-ts'; +import { Address, BigInt, Bytes } from '@graphprotocol/graph-ts'; import { VToken as VTokenContract } from '../../generated/PoolRegistry/VToken'; import { BEP20 } from '../../generated/PoolRegistry/BEP20'; @@ -28,6 +28,7 @@ import { createPool, createRewardDistributor, } from './create'; +import { vWETHLiquidStakedETHAddress, vWETHCoreAddress } from '../constants/addresses'; import { getMarketPosition, getMarket } from './get'; // BIFI was delisted before it was listed. Creation ignores this market. @@ -145,6 +146,22 @@ export const getOrCreateRewardDistributor = ( return rewardsDistributor as RewardsDistributor; }; +function getOrCreateWrappedEthToken(): Token { + const underlyingTokenAddress = Address.fromBytes( + Bytes.fromHexString('0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9'), + ); + let tokenEntity = Token.load(getTokenId(underlyingTokenAddress)); + if (!tokenEntity) { + tokenEntity = new Token(getTokenId(underlyingTokenAddress)); + tokenEntity.address = underlyingTokenAddress; + tokenEntity.name = 'Wrapped Ether'; + tokenEntity.symbol = 'WETH '; + tokenEntity.decimals = 18; + tokenEntity.save(); + } + return tokenEntity; +} + /** * Creates and Token object with symbol and address * @@ -153,6 +170,9 @@ export const getOrCreateRewardDistributor = ( */ export function getOrCreateToken(asset: Address): Token { let tokenEntity = Token.load(getTokenId(asset)); + if (asset.equals(vWETHCoreAddress) || asset.equals(vWETHLiquidStakedETHAddress)) { + return getOrCreateWrappedEthToken(); + } if (!tokenEntity) { const erc20 = BEP20.bind(asset); diff --git a/subgraphs/venus/src/operations/getOrCreate.ts b/subgraphs/venus/src/operations/getOrCreate.ts index e7cc440e..8cdda6df 100644 --- a/subgraphs/venus/src/operations/getOrCreate.ts +++ b/subgraphs/venus/src/operations/getOrCreate.ts @@ -61,10 +61,6 @@ export function getOrCreateMarket(marketAddress: Address, event: ethereum.Event) tokenEntity.decimals = 18; tokenEntity.save(); market.underlyingToken = tokenEntity.id; - } else if (marketAddress.equals(vwbETHAddress)) { - market.underlyingToken = getOrCreateToken( - Address.fromBytes(Bytes.fromHexString('0x9c37E59Ba22c4320547F00D4f1857AF1abd1Dd6f')), - ).id; } else { market.underlyingToken = getOrCreateToken(vTokenContract.underlying()).id; } @@ -167,6 +163,19 @@ export function getOrCreateMarketPosition( return { entity: marketPosition, created }; } +function getOrCreateWrappedEthToken(): Token { + const underlyingTokenAddress = Address.fromBytes( + Bytes.fromHexString('0x9c37E59Ba22c4320547F00D4f1857AF1abd1Dd6f'), + ); + const tokenEntity = new Token(getTokenId(underlyingTokenAddress)); + tokenEntity.address = underlyingTokenAddress; + tokenEntity.name = 'Wrapped Binance Beacon ETH'; + tokenEntity.symbol = 'wBETH'; + tokenEntity.decimals = 18; + tokenEntity.save(); + return tokenEntity; +} + /** * Creates and Token object with symbol and address * @@ -177,13 +186,17 @@ export function getOrCreateToken(asset: Address): Token { let tokenEntity = Token.load(getTokenId(asset)); if (!tokenEntity) { - const erc20 = BEP20.bind(asset); - tokenEntity = new Token(getTokenId(asset)); - tokenEntity.address = asset; - tokenEntity.name = erc20.name(); - tokenEntity.symbol = erc20.symbol(); - tokenEntity.decimals = erc20.decimals(); - tokenEntity.save(); + if (asset.equals(vwbETHAddress)) { + return getOrCreateWrappedEthToken(); + } else { + const erc20 = BEP20.bind(asset); + tokenEntity = new Token(getTokenId(asset)); + tokenEntity.address = asset; + tokenEntity.name = erc20.name(); + tokenEntity.symbol = erc20.symbol(); + tokenEntity.decimals = erc20.decimals(); + tokenEntity.save(); + } } return tokenEntity; }