From 445ec8a84a6d43025983b84c47750ed98da0d2c8 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 | 21 ++++++++++++------ .../src/operations/getOrCreate.ts | 22 ++++++++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/subgraphs/isolated-pools/src/operations/create.ts b/subgraphs/isolated-pools/src/operations/create.ts index 07eea54b..96f7bafb 100644 --- a/subgraphs/isolated-pools/src/operations/create.ts +++ b/subgraphs/isolated-pools/src/operations/create.ts @@ -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..6f60641b 100644 --- a/subgraphs/isolated-pools/src/operations/getOrCreate.ts +++ b/subgraphs/isolated-pools/src/operations/getOrCreate.ts @@ -146,7 +146,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 +177,6 @@ function getOrCreateWrappedEthToken(): Token { } return tokenEntity; } - /** * Creates and Token object with symbol and address * @@ -170,9 +185,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);