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
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
@@ -33,8 +33,6 @@ import {
vagEURAddress,
vankrBNBDeFiAddress,
vankrBNBLiquidStakedBNBAddress,
vWETHLiquidStakedETHAddress,
vWETHCoreAddress,
} from '../constants/addresses';
import { getOrCreateMarketReward, getOrCreateToken } from './getOrCreate';
import { getTokenPriceInCents, valueOrNotAvailableIntIfReverted } from '../utilities';
@@ -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;
}
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';
@@ -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.
@@ -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
*
@@ -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);
35 changes: 24 additions & 11 deletions subgraphs/venus/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
@@ -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;
}
@@ -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
*
@@ -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;
}

Unchanged files with check annotations Beta

import assert from 'assert';
export const assertEqual = (
entity: any,

Check warning on line 4 in packages/utils/src/testing.ts

GitHub Actions / lint

Unexpected any. Specify a different type
contractValue: any,

Check warning on line 5 in packages/utils/src/testing.ts

GitHub Actions / lint

Unexpected any. Specify a different type
key: string,
transform?: (val: any) => any,

Check warning on line 7 in packages/utils/src/testing.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 7 in packages/utils/src/testing.ts

GitHub Actions / lint

Unexpected any. Specify a different type
) => {
const subgraphValue = transform ? transform(entity[key]) : entity[key]?.toString();
try {
}
};
export const tryCall = async (func: () => any, defaultValue: any) => {

Check warning on line 24 in packages/utils/src/testing.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 24 in packages/utils/src/testing.ts

GitHub Actions / lint

Unexpected any. Specify a different type
try {
return await func();
} catch (e) {
import BigNumber from 'bignumber.js';
import { ethers } from 'hardhat';
export async function enfranchiseAccount(account: any, amount: BigNumber) {

Check warning on line 4 in subgraphs/venus-governance/tests/integration/utils/voter.ts

GitHub Actions / lint

Unexpected any. Specify a different type
const xvs = await ethers.getContract('XVS');
const xvsVaultProxy = await ethers.getContract('XVSVaultProxy');
const xvsVault = await ethers.getContractAt('XVSVault', xvsVaultProxy.address);