Skip to content

Commit

Permalink
fix: hardchade underlying ankrstakedbnb token to avoid errors queryin…
Browse files Browse the repository at this point in the history
…g before existence
  • Loading branch information
coreyar committed Dec 18, 2024
1 parent 8172c28 commit 445ec8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
21 changes: 14 additions & 7 deletions subgraphs/isolated-pools/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
}

Expand All @@ -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;
}
Expand Down
22 changes: 17 additions & 5 deletions subgraphs/isolated-pools/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
Expand All @@ -161,7 +177,6 @@ function getOrCreateWrappedEthToken(): Token {
}
return tokenEntity;
}

/**
* Creates and Token object with symbol and address
*
Expand All @@ -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);
Expand Down

0 comments on commit 445ec8a

Please sign in to comment.