Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hardchade underlying weth token to avoid errors querying before existence #225

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions subgraphs/isolated-pools/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import {
vagEURAddress,
vankrBNBDeFiAddress,
vankrBNBLiquidStakedBNBAddress,
vWETHLiquidStakedETHAddress,
vWETHCoreAddress,
} from '../constants/addresses';
import { getOrCreateMarketReward, getOrCreateToken } from './getOrCreate';
import { getTokenPriceInCents, valueOrNotAvailableIntIfReverted } from '../utilities';
Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 21 additions & 1 deletion subgraphs/isolated-pools/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
*
Expand All @@ -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);
Expand Down
35 changes: 24 additions & 11 deletions subgraphs/venus/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
*
Expand All @@ -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;
}
Loading