diff --git a/subgraphs/venus/config/index.ts b/subgraphs/venus/config/index.ts index 0d63790e..724e01e4 100644 --- a/subgraphs/venus/config/index.ts +++ b/subgraphs/venus/config/index.ts @@ -25,7 +25,7 @@ const main = () => { chapel: { network: 'chapel', comptrollerAddress: bscTestnetCoreDeployments.addresses.Unitroller, - startBlock: '2802485', + startBlock: '2802486', wbETHAddress: '0xf9f98365566f4d55234f24b99caa1afbe6428d44', vTRXAddress: '0x369fea97f6fb7510755dca389088d9e2e2819278', vTUSDOldAddress: '0x3a00d9b02781f47d033bad62edc55fbf8d083fb0', diff --git a/subgraphs/venus/package.json b/subgraphs/venus/package.json index 8ec7b070..b29c5f46 100644 --- a/subgraphs/venus/package.json +++ b/subgraphs/venus/package.json @@ -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", diff --git a/subgraphs/venus/schema.graphql b/subgraphs/venus/schema.graphql index f8002a22..4f94809a 100644 --- a/subgraphs/venus/schema.graphql +++ b/subgraphs/venus/schema.graphql @@ -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! } """ diff --git a/subgraphs/venus/src/mappings/comptroller.ts b/subgraphs/venus/src/mappings/comptroller.ts index da1aed11..8ee5be97 100644 --- a/subgraphs/venus/src/mappings/comptroller.ts +++ b/subgraphs/venus/src/mappings/comptroller.ts @@ -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, @@ -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(); } diff --git a/subgraphs/venus/subgraph-client/queries/accountByIdQuery.graphql b/subgraphs/venus/subgraph-client/queries/accountByIdQuery.graphql index 934aa466..257f0898 100644 --- a/subgraphs/venus/subgraph-client/queries/accountByIdQuery.graphql +++ b/subgraphs/venus/subgraph-client/queries/accountByIdQuery.graphql @@ -1,6 +1,7 @@ query AccountById($id: ID!) { account(id: $id) { id + address tokens { id vTokenBalanceMantissa diff --git a/subgraphs/venus/subgraph-client/queries/accountsInAddressQuery.graphql b/subgraphs/venus/subgraph-client/queries/accountsInAddressQuery.graphql index 27d872bd..e294ac63 100644 --- a/subgraphs/venus/subgraph-client/queries/accountsInAddressQuery.graphql +++ b/subgraphs/venus/subgraph-client/queries/accountsInAddressQuery.graphql @@ -1,6 +1,7 @@ query Accounts { accounts { id + address tokens { id } diff --git a/subgraphs/venus/subgraph-client/queries/comptroller.graphql b/subgraphs/venus/subgraph-client/queries/comptroller.graphql index fe9d27b8..818dfe28 100644 --- a/subgraphs/venus/subgraph-client/queries/comptroller.graphql +++ b/subgraphs/venus/subgraph-client/queries/comptroller.graphql @@ -1,9 +1,9 @@ query Comptrollers { comptrollers { id + address priceOracle closeFactorMantissa liquidationIncentive - maxAssets } } diff --git a/subgraphs/venus/subgraph-client/queries/marketByIdQuery.graphql b/subgraphs/venus/subgraph-client/queries/marketByIdQuery.graphql index 7bfb64dc..d04dd5e1 100644 --- a/subgraphs/venus/subgraph-client/queries/marketByIdQuery.graphql +++ b/subgraphs/venus/subgraph-client/queries/marketByIdQuery.graphql @@ -1,6 +1,7 @@ query MarketById($id: ID!) { market(id: $id) { id + address isListed borrowRateMantissa cashMantissa diff --git a/subgraphs/venus/subgraph-client/queries/marketPositionByAccount.graphql b/subgraphs/venus/subgraph-client/queries/marketPositionByAccount.graphql index ee12c23f..c407ef07 100644 --- a/subgraphs/venus/subgraph-client/queries/marketPositionByAccount.graphql +++ b/subgraphs/venus/subgraph-client/queries/marketPositionByAccount.graphql @@ -3,9 +3,11 @@ query MarketPositionByAccountId($accountId: String!) { id market { id + address } account { id + address } enteredMarket totalUnderlyingRedeemedMantissa diff --git a/subgraphs/venus/subgraph-client/queries/marketPositionByAccountAndMarket.graphql b/subgraphs/venus/subgraph-client/queries/marketPositionByAccountAndMarket.graphql index 7e65d949..e085ecf1 100644 --- a/subgraphs/venus/subgraph-client/queries/marketPositionByAccountAndMarket.graphql +++ b/subgraphs/venus/subgraph-client/queries/marketPositionByAccountAndMarket.graphql @@ -3,9 +3,11 @@ query MarketPositionByAccountAndMarketQuery($id: ID!) { id market { id + address } account { id + address hasBorrowed } enteredMarket diff --git a/subgraphs/venus/subgraph-client/queries/marketPositions.graphql b/subgraphs/venus/subgraph-client/queries/marketPositions.graphql index 363da64f..e019a767 100644 --- a/subgraphs/venus/subgraph-client/queries/marketPositions.graphql +++ b/subgraphs/venus/subgraph-client/queries/marketPositions.graphql @@ -4,10 +4,12 @@ query MarketPositions($first: Int, $skip: Int) { market { id symbol + address borrowIndex } account { id + address } enteredMarket totalUnderlyingRedeemedMantissa diff --git a/subgraphs/venus/subgraph-client/queries/marketPositionsWithBorrowByMarketId.graphql b/subgraphs/venus/subgraph-client/queries/marketPositionsWithBorrowByMarketId.graphql index a26e6081..9d9a3fe4 100644 --- a/subgraphs/venus/subgraph-client/queries/marketPositionsWithBorrowByMarketId.graphql +++ b/subgraphs/venus/subgraph-client/queries/marketPositionsWithBorrowByMarketId.graphql @@ -3,6 +3,7 @@ query MarketPositionsWithBorrowByMarketId($first: Int, $skip: Int, $marketId: St id account { id + address } storedBorrowBalanceMantissa borrowIndex diff --git a/subgraphs/venus/subgraph-client/queries/marketPositionsWithSupplyByMarketId.graphql b/subgraphs/venus/subgraph-client/queries/marketPositionsWithSupplyByMarketId.graphql index 5bc6ce60..1935ce9d 100644 --- a/subgraphs/venus/subgraph-client/queries/marketPositionsWithSupplyByMarketId.graphql +++ b/subgraphs/venus/subgraph-client/queries/marketPositionsWithSupplyByMarketId.graphql @@ -3,6 +3,7 @@ query MarketPositionsWithSupplyByMarketId($first: Int, $skip: Int, $marketId: St id account { id + address } vTokenBalanceMantissa } diff --git a/subgraphs/venus/subgraph-client/queries/marketsQuery.graphql b/subgraphs/venus/subgraph-client/queries/marketsQuery.graphql index 9a9a1a55..74d61ea8 100644 --- a/subgraphs/venus/subgraph-client/queries/marketsQuery.graphql +++ b/subgraphs/venus/subgraph-client/queries/marketsQuery.graphql @@ -1,6 +1,7 @@ query Markets { markets { id + address name symbol vTokenDecimals diff --git a/subgraphs/venus/tests/mocks.ts b/subgraphs/venus/tests/mocks.ts index 85391b2f..27a6a7a7 100644 --- a/subgraphs/venus/tests/mocks.ts +++ b/subgraphs/venus/tests/mocks.ts @@ -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), ]); @@ -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)]) diff --git a/subgraphs/venus/tests/scripts/checkComptroller.ts b/subgraphs/venus/tests/scripts/checkComptroller.ts index 7f5d300f..b1aed2bb 100644 --- a/subgraphs/venus/tests/scripts/checkComptroller.ts +++ b/subgraphs/venus/tests/scripts/checkComptroller.ts @@ -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); diff --git a/subgraphs/venus/tests/scripts/checkMarketPositions.ts b/subgraphs/venus/tests/scripts/checkMarketPositions.ts index 778677ae..b5b14d00 100644 --- a/subgraphs/venus/tests/scripts/checkMarketPositions.ts +++ b/subgraphs/venus/tests/scripts/checkMarketPositions.ts @@ -10,20 +10,24 @@ const checkMarketPositions = async ( subgraphClient: ReturnType, ) => { 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()}`, ); @@ -31,7 +35,7 @@ const checkMarketPositions = async ( console.log(e.message); } const borrowBalanceStored = await vTokenContract.borrowBalanceStored( - marketPosition.account.id, + marketPosition.account.address, ); const updatedSubgraphValue = BigNumber.from(marketPosition.storedBorrowBalanceMantissa) @@ -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); diff --git a/subgraphs/venus/tests/scripts/checkMarkets.ts b/subgraphs/venus/tests/scripts/checkMarkets.ts index ab0290c1..93c9f675 100644 --- a/subgraphs/venus/tests/scripts/checkMarkets.ts +++ b/subgraphs/venus/tests/scripts/checkMarkets.ts @@ -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, @@ -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, @@ -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(), ''), @@ -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(), @@ -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), ); @@ -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), @@ -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'); @@ -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}`); @@ -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}`);