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

Remove max assets and update test scripts #238

Merged
merged 5 commits into from
Jan 15, 2025
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
2 changes: 1 addition & 1 deletion subgraphs/venus/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const main = () => {
chapel: {
network: 'chapel',
comptrollerAddress: bscTestnetCoreDeployments.addresses.Unitroller,
startBlock: '2802485',
startBlock: '2802486',
wbETHAddress: '0xf9f98365566f4d55234f24b99caa1afbe6428d44',
vTRXAddress: '0x369fea97f6fb7510755dca389088d9e2e2819278',
vTUSDOldAddress: '0x3a00d9b02781f47d033bad62edc55fbf8d083fb0',
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/venus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@venusprotocol/core-pool-subgraph",
"version": "1.2.1-testnet.1",
"version": "1.2.1",
"license": "MIT",
"repository": {
"url": "https://github.com/VenusProtocol/subgraphs",
Expand Down
2 changes: 0 additions & 2 deletions subgraphs/venus/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ type Comptroller @entity {
closeFactorMantissa: BigInt!
"The percent bonus liquidators get for liquidating"
liquidationIncentive: BigInt!
"Max assets a single user can enter (not used in comptroller logic)"
maxAssets: BigInt!
}

"""
Expand Down
3 changes: 1 addition & 2 deletions subgraphs/venus/src/mappings/comptroller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable prefer-const */
// to satisfy AS compiler
import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts';
import { Address, ethereum } from '@graphprotocol/graph-ts';
import { Comptroller as ComptrollerContract } from '../../generated/templates/VToken/Comptroller';
import {
DistributedBorrowerVenus,
Expand Down Expand Up @@ -31,7 +31,6 @@ export function handleInitialization(block: ethereum.Block): void {
comptroller.priceOracle = nullAddress;
comptroller.closeFactorMantissa = zeroBigInt32;
comptroller.liquidationIncentive = zeroBigInt32;
comptroller.maxAssets = BigInt.fromI32(20);
comptroller.save();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query AccountById($id: ID!) {
account(id: $id) {
id
address
tokens {
id
vTokenBalanceMantissa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query Accounts {
accounts {
id
address
tokens {
id
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
query Comptrollers {
comptrollers {
id
address
priceOracle
closeFactorMantissa
liquidationIncentive
maxAssets
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query MarketById($id: ID!) {
market(id: $id) {
id
address
isListed
borrowRateMantissa
cashMantissa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ query MarketPositionByAccountId($accountId: String!) {
id
market {
id
address
}
account {
id
address
}
enteredMarket
totalUnderlyingRedeemedMantissa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ query MarketPositionByAccountAndMarketQuery($id: ID!) {
id
market {
id
address
}
account {
id
address
hasBorrowed
}
enteredMarket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ query MarketPositions($first: Int, $skip: Int) {
market {
id
symbol
address
borrowIndex
}
account {
id
address
}
enteredMarket
totalUnderlyingRedeemedMantissa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ query MarketPositionsWithBorrowByMarketId($first: Int, $skip: Int, $marketId: St
id
account {
id
address
}
storedBorrowBalanceMantissa
borrowIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ query MarketPositionsWithSupplyByMarketId($first: Int, $skip: Int, $marketId: St
id
account {
id
address
}
vTokenBalanceMantissa
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query Markets {
markets {
id
address
name
symbol
vTokenDecimals
Expand Down
8 changes: 0 additions & 8 deletions subgraphs/venus/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ export const createComptrollerMock = (vTokens: Address[]): void => {
'liquidationIncentiveMantissa():(uint256)',
).returns([ethereum.Value.fromI32(1)]);

createMockedFunction(comptrollerAddress, 'maxAssets', 'maxAssets():(uint256)').returns([
ethereum.Value.fromI32(10),
]);

createMockedFunction(comptrollerAddress, 'oracle', 'oracle():(address)').returns([
ethereum.Value.fromAddress(priceOracleAddress),
]);
Expand All @@ -221,10 +217,6 @@ export const createComptrollerMock = (vTokens: Address[]): void => {
'liquidationIncentiveMantissa():(uint256)',
).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1000000000000000'))]);

createMockedFunction(comptrollerAddress, 'maxAssets', 'maxAssets():(uint256)').returns([
ethereum.Value.fromUnsignedBigInt(BigInt.fromString('999')),
]);

vTokens.forEach(vToken => {
createMockedFunction(comptrollerAddress, 'supplyCaps', 'supplyCaps(address):(uint256)')
.withArgs([ethereum.Value.fromAddress(vToken)])
Expand Down
4 changes: 1 addition & 3 deletions subgraphs/venus/tests/scripts/checkComptroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ const checkComptroller = async (
) => {
const { comptroller } = await subgraphClient.getComptroller();
const comptrollerContract = new ethers.Contract(comptroller.id, ComptrollerAbi, provider);
const [priceOracle, closeFactorMantissa, liquidationIncentive, maxAssets] = await Promise.all([
const [priceOracle, closeFactorMantissa, liquidationIncentive] = await Promise.all([
comptrollerContract.oracle(),
comptrollerContract.closeFactorMantissa(),
comptrollerContract.liquidationIncentiveMantissa(),
comptrollerContract.maxAssets(),
]);
try {
assertEqual(comptroller, priceOracle, 'priceOracle', getAddress);
assertEqual(comptroller, closeFactorMantissa, 'closeFactorMantissa');
assertEqual(comptroller, liquidationIncentive, 'liquidationIncentive');
assertEqual(comptroller, maxAssets, 'maxAssets');
console.log(`correct values on comptroller entity - ${comptroller.id}`);
} catch (e) {
console.log(e.message);
Expand Down
16 changes: 10 additions & 6 deletions subgraphs/venus/tests/scripts/checkMarketPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,32 @@ const checkMarketPositions = async (
subgraphClient: ReturnType<typeof createSubgraphClient>,
) => {
let skip = 0;
while (skip >= 0) {
while (skip >= 0 && skip <= 5000) {
console.log(`processed ${skip * 25}...`);
const { marketPositions } = await subgraphClient.getMarketPositions({
first: 25,
skip: skip * 25,
});
for (const marketPosition of marketPositions) {
const vTokenContract = new ethers.Contract(marketPosition.market.id, VBep20Abi.abi, provider);
const accountBalance = await vTokenContract.balanceOf(marketPosition.account.id);
const vTokenContract = new ethers.Contract(
marketPosition.market.address,
VBep20Abi.abi,
provider,
);
const accountBalance = await vTokenContract.balanceOf(marketPosition.account.address);
try {
assert.equal(
marketPosition.vTokenBalanceMantissa,
accountBalance.toString(),
`incorrect supply balance for account ${marketPosition.account.id} in market ${marketPosition.market.symbol} ${marketPosition.market.id}. Subgraph Value: ${
`incorrect supply balance for account ${marketPosition.account.address} in market ${marketPosition.market.symbol} ${marketPosition.market.address}. Subgraph Value: ${
marketPosition.vTokenBalanceMantissa
}, contractValue: ${accountBalance.toString()}`,
);
} catch (e) {
console.log(e.message);
}
const borrowBalanceStored = await vTokenContract.borrowBalanceStored(
marketPosition.account.id,
marketPosition.account.address,
);

const updatedSubgraphValue = BigNumber.from(marketPosition.storedBorrowBalanceMantissa)
Expand All @@ -45,7 +49,7 @@ const checkMarketPositions = async (
updatedSubgraphValue,
borrowBalanceStored.toString(),
`
incorrect borrow balance on account ${marketPosition.account.id} on market ${marketPosition.market.symbol} ${marketPosition.market.id}, accountBorrowIndex: ${marketPosition.borrowIndex}, marketBorrowIndex ${marketPosition.market.borrowIndex} subgraphValue: ${marketPosition.storedBorrowBalanceMantissa} contractValue: ${borrowBalanceStored}`,
incorrect borrow balance on account ${marketPosition.account.address} on market ${marketPosition.market.symbol} ${marketPosition.market.address}, accountBorrowIndex: ${marketPosition.borrowIndex}, marketBorrowIndex ${marketPosition.market.borrowIndex} subgraphValue: ${marketPosition.storedBorrowBalanceMantissa} contractValue: ${borrowBalanceStored}`,
);
} catch (e) {
console.log(e.message);
Expand Down
26 changes: 13 additions & 13 deletions subgraphs/venus/tests/scripts/checkMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const countSuppliers = async (
) => {
let supplierCount = 0;
let page = 0;
while (page >= 0) {
while (page >= 0 && page <= 50) {
const { marketPositions } = await subgraphClient.getMarketPositionsWithSupplyByMarketId({
marketId: marketAddress,
page,
Expand All @@ -46,7 +46,7 @@ const countBorrower = async (
) => {
let borrowerCount = 0;
let page = 0;
while (page >= 0) {
while (page >= 0 && page <= 50) {
const { marketPositions } = await subgraphClient.getMarketPositionsWithBorrowByMarketId({
marketId: marketAddress,
page,
Expand All @@ -69,7 +69,7 @@ const checkMarkets = async (
) => {
const { markets } = await subgraphClient.getMarkets();
for (const market of markets) {
const vTokenContract = new ethers.Contract(market.id, VBep20Abi, provider);
const vTokenContract = new ethers.Contract(market.address, VBep20Abi, provider);
const [comptrollerAddress, underlyingAddress] = await Promise.all([
vTokenContract.comptroller(),
tryCall(async () => await vTokenContract.underlying(), ''),
Expand Down Expand Up @@ -105,7 +105,7 @@ const checkMarkets = async (
vTokenContract.name(),
vTokenContract.symbol(),
vTokenContract.decimals(),
comptrollerContract.markets(market.id),
comptrollerContract.markets(market.address),
vTokenContract.getCash(),
vTokenContract.exchangeRateStored(),
vTokenContract.interestRateModel(),
Expand All @@ -118,21 +118,21 @@ const checkMarkets = async (
]);

const supplyState = await tryCall(
async () => await comptrollerContract.venusSupplyState(market.id),
async () => await comptrollerContract.venusSupplyState(market.address),
{ block: BigNumber.from(0), index: BigNumber.from(0) },
);

const borrowState = await tryCall(
async () => await comptrollerContract.venusBorrowState(market.id),
async () => await comptrollerContract.venusBorrowState(market.address),
{ block: BigNumber.from(0), index: BigNumber.from(0) },
);

const xvsSupplySpeeds = await tryCall(
async () => await comptrollerContract.venusSupplySpeeds(market.id),
async () => await comptrollerContract.venusSupplySpeeds(market.address),
BigNumber.from(0),
);
const xvsBorrowSpeeds = await await tryCall(
async () => comptrollerContract.venusBorrowSpeeds(market.id),
async () => comptrollerContract.venusBorrowSpeeds(market.address),
BigNumber.from(0),
);

Expand All @@ -147,7 +147,7 @@ const checkMarkets = async (

const underlyingPrice = await tryCall(
async () =>
await priceOracleContract.getUnderlyingPrice(market.id, {
await priceOracleContract.getUnderlyingPrice(market.address, {
blockTag: +market.lastUnderlyingPriceBlockNumber,
}),
BigNumber.from(0),
Expand Down Expand Up @@ -183,8 +183,8 @@ const checkMarkets = async (
const underlyingPriceInCents = underlyingPrice.div(10n ** BigInt(bdFactor));
assertEqual(market, underlyingPriceInCents, 'lastUnderlyingPriceCents');

const totalSuppliers = await countSuppliers(subgraphClient, market.id);
const totalBorrowers = await countBorrower(subgraphClient, market.id);
const totalSuppliers = await countSuppliers(subgraphClient, market.address);
const totalBorrowers = await countBorrower(subgraphClient, market.address);
assertEqual(market, totalSuppliers, 'supplierCount');
assertEqual(market, totalBorrowers, 'borrowerCount');

Expand All @@ -195,7 +195,7 @@ const checkMarkets = async (
market.totalSupplyVTokenMantissa,
`
incorrect total supply market ${market.symbol} ${
market.id
market.address
} contract ${totalSupply.toString()} subgraph ${market.totalSupplyVTokenMantissa.toString()}`,
);
console.log(`correct supply for ${market.symbol}`);
Expand All @@ -213,7 +213,7 @@ const checkMarkets = async (
market.totalBorrowsMantissa.toString(),
`
incorrect total borrow on market ${market.symbol} ${
market.id
market.address
} contract ${totalBorrows.toString()} subgraph ${market.totalBorrowsMantissa.toString()}`,
);
console.log(`correct borrow for ${market.symbol}`);
Expand Down
Loading