From 002114147e6611e37dee05f52c3cbb79ff9e4a17 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Wed, 18 Dec 2024 11:40:54 -0300 Subject: [PATCH] fix: hardchade underlying ankrstakedbnb token to avoid errors querying before existence --- .../isolated-pools/src/operations/create.ts | 23 ++++++++++++------- .../src/operations/getOrCreate.ts | 23 ++++++++++++++----- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/subgraphs/isolated-pools/src/operations/create.ts b/subgraphs/isolated-pools/src/operations/create.ts index 07eea54b..3f48495a 100644 --- a/subgraphs/isolated-pools/src/operations/create.ts +++ b/subgraphs/isolated-pools/src/operations/create.ts @@ -1,4 +1,4 @@ -import { Address, BigInt, Bytes } from '@graphprotocol/graph-ts'; +import { Address, BigInt } from '@graphprotocol/graph-ts'; import { Comptroller as ComptrollerContract } from '../../generated/PoolRegistry/Comptroller'; import { PoolRegistry as PoolRegistryContract } from '../../generated/PoolRegistry/PoolRegistry'; @@ -33,8 +33,15 @@ import { vagEURAddress, vankrBNBDeFiAddress, vankrBNBLiquidStakedBNBAddress, + vWETHLiquidStakedETHAddress, + vWETHCoreAddress, } from '../constants/addresses'; -import { getOrCreateMarketReward, getOrCreateToken } from './getOrCreate'; +import { + getOrCreateMarketReward, + getOrCreateToken, + getOrCreateWrappedEthToken, + getOrCreateAnkrStakedBNBToken, +} from './getOrCreate'; import { getTokenPriceInCents, valueOrNotAvailableIntIfReverted } from '../utilities'; import { getAccountId, @@ -175,16 +182,12 @@ export function createMarket( } if (vTokenAddress.equals(vankrBNBLiquidStakedBNBAddress)) { - market.underlyingToken = getOrCreateToken( - Address.fromBytes(Bytes.fromHexString('0x5269b7558D3d5E113010Ef1cFF0901c367849CC9')), - ).id; + market.underlyingToken = getOrCreateAnkrStakedBNBToken().id; market.symbol = 'vankrBNB_LiquidStakedBNB'; } if (vTokenAddress.equals(vankrBNBDeFiAddress)) { - market.underlyingToken = getOrCreateToken( - Address.fromBytes(Bytes.fromHexString('0x5269b7558D3d5E113010Ef1cFF0901c367849CC9')), - ).id; + market.underlyingToken = getOrCreateAnkrStakedBNBToken().id; market.symbol = 'vankrBNB_DeFi'; } @@ -193,6 +196,10 @@ export function createMarket( market.symbol = 'vslisBNB_LiquidStakedBNB'; } + if (vTokenAddress.equals(vWETHLiquidStakedETHAddress) || vTokenAddress.equals(vWETHCoreAddress)) { + market.underlyingToken = getOrCreateWrappedEthToken().id; + } + market.save(); return market; } diff --git a/subgraphs/isolated-pools/src/operations/getOrCreate.ts b/subgraphs/isolated-pools/src/operations/getOrCreate.ts index 5e141db1..94e33981 100644 --- a/subgraphs/isolated-pools/src/operations/getOrCreate.ts +++ b/subgraphs/isolated-pools/src/operations/getOrCreate.ts @@ -28,7 +28,6 @@ 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. @@ -146,7 +145,23 @@ export const getOrCreateRewardDistributor = ( return rewardsDistributor as RewardsDistributor; }; -function getOrCreateWrappedEthToken(): Token { +export function getOrCreateAnkrStakedBNBToken(): Token { + const underlyingTokenAddress = Address.fromBytes( + Bytes.fromHexString('0x5269b7558D3d5E113010Ef1cFF0901c367849CC9'), + ); + let tokenEntity = Token.load(getTokenId(underlyingTokenAddress)); + if (!tokenEntity) { + tokenEntity = new Token(getTokenId(underlyingTokenAddress)); + tokenEntity.address = underlyingTokenAddress; + tokenEntity.name = 'Ankr Staked BNB'; + tokenEntity.symbol = 'ankrBNB '; + tokenEntity.decimals = 18; + tokenEntity.save(); + } + return tokenEntity; +} + +export function getOrCreateWrappedEthToken(): Token { const underlyingTokenAddress = Address.fromBytes( Bytes.fromHexString('0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9'), ); @@ -161,7 +176,6 @@ function getOrCreateWrappedEthToken(): Token { } return tokenEntity; } - /** * Creates and Token object with symbol and address * @@ -170,9 +184,6 @@ function getOrCreateWrappedEthToken(): Token { */ 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);