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 0021141
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
23 changes: 15 additions & 8 deletions subgraphs/isolated-pools/src/operations/create.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down 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
23 changes: 17 additions & 6 deletions subgraphs/isolated-pools/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'),
);
Expand All @@ -161,7 +176,6 @@ function getOrCreateWrappedEthToken(): Token {
}
return tokenEntity;
}

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

0 comments on commit 0021141

Please sign in to comment.