Skip to content

Commit

Permalink
Merge pull request #225 from VenusProtocol/hardcode-updated-weth-unde…
Browse files Browse the repository at this point in the history
…rlying

fix: hardchade underlying weth token to avoid errors querying before existence
  • Loading branch information
coreyar authored Dec 18, 2024
2 parents e1f4e1c + e4c2adf commit 55565e1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
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;
}

0 comments on commit 55565e1

Please sign in to comment.