From 9eeb93e563a7c1746e9e9cbc03ee43486278338c Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Tue, 14 Nov 2023 12:24:41 -0300 Subject: [PATCH 1/6] refactor: use templates for network specific variables --- subgraphs/venus/config/bsc.json | 5 ++-- subgraphs/venus/config/chapel.json | 5 ++-- subgraphs/venus/config/docker.json | 5 ++-- subgraphs/venus/package.json | 8 +++--- subgraphs/venus/src/constants/addresses.ts | 12 ++++---- subgraphs/venus/src/constants/config-template | 4 +++ subgraphs/venus/src/mappings/comptroller.ts | 28 +++++++++---------- subgraphs/venus/template.yaml | 2 +- subgraphs/venus/tests/Comptroller.test.ts | 8 ++---- subgraphs/venus/tests/constants/index.ts | 5 ++++ yarn.lock | 6 ---- 11 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 subgraphs/venus/src/constants/config-template create mode 100644 subgraphs/venus/tests/constants/index.ts diff --git a/subgraphs/venus/config/bsc.json b/subgraphs/venus/config/bsc.json index 20b93ee9..5027b3a5 100644 --- a/subgraphs/venus/config/bsc.json +++ b/subgraphs/venus/config/bsc.json @@ -1,5 +1,6 @@ { "network": "bsc", - "address": "0xfd36e2c2a6789db23113685031d7f16329158384", - "startBlock": "2470000" + "comptrollerAddress": "0xfd36e2c2a6789db23113685031d7f16329158384", + "startBlock": "2470000", + "vBnbAddress": "0xA07c5b74C9B40447a954e1466938b865b6BBea36" } diff --git a/subgraphs/venus/config/chapel.json b/subgraphs/venus/config/chapel.json index db884110..cb7990fd 100644 --- a/subgraphs/venus/config/chapel.json +++ b/subgraphs/venus/config/chapel.json @@ -1,5 +1,6 @@ { "network": "bsc-testnet", - "address": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D", - "startBlock": "2470000" + "comptrollerAddress": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D", + "startBlock": "2470000", + "vBnbAddress": "0x2E7222e51c0f6e98610A1543Aa3836E092CDe62c" } diff --git a/subgraphs/venus/config/docker.json b/subgraphs/venus/config/docker.json index 3089b8e5..a61df7e2 100644 --- a/subgraphs/venus/config/docker.json +++ b/subgraphs/venus/config/docker.json @@ -1,5 +1,6 @@ { "network": "bsc-testnet", - "address": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D", - "startBlock": "0" + "comptrollerAddress": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D", + "startBlock": "0", + "vBnbAddress": "0xA07c5b74C9B40447a954e1466938b865b6BBea36" } diff --git a/subgraphs/venus/package.json b/subgraphs/venus/package.json index d393c9dc..8eadf038 100644 --- a/subgraphs/venus/package.json +++ b/subgraphs/venus/package.json @@ -16,10 +16,10 @@ "build:bsc": "graph build --ipfs https://api.thegraph.com/ipfs/ ", "deploy:integration": "graph deploy venusprotocol/venus-subgraph --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020/", "deploy:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml && npx mustache config/docker.json src/constants/config-template > src/constants/config.ts && npx graph deploy venusprotocol/venus-subgraph --ipfs http://ipfs:5001 --node http://graph-node:8020/ --version-label ci", - "deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-subgraph -chapel --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-subgraph e --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "prepare:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml", - "prepare:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml", + "deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-subgraph-chapel --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "prepare:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml && npx mustache config/docker.json src/constants/config-template > src/constants/config.ts", + "prepare:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts", "prepare:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts", "test": "graph test", "test:integration": "true" diff --git a/subgraphs/venus/src/constants/addresses.ts b/subgraphs/venus/src/constants/addresses.ts index 291e0b8c..c8f66fb0 100644 --- a/subgraphs/venus/src/constants/addresses.ts +++ b/subgraphs/venus/src/constants/addresses.ts @@ -1,8 +1,10 @@ import { Address } from '@graphprotocol/graph-ts'; -export const vBnbAddress = Address.fromString('0xA07c5b74C9B40447a954e1466938b865b6BBea36'); -export const interestRateModelAddress = Address.fromString( - '0x594942C0e62eC577889777424CD367545C796A74', -); -export const comptrollerAddress = Address.fromString('0xfd36e2c2a6789db23113685031d7f16329158384'); +import { + comptrollerAddress as comptrollerAddressString, + vBnbAddress as vBnbAddressString, +} from './config'; + +export const vBnbAddress = Address.fromString(vBnbAddressString); +export const comptrollerAddress = Address.fromString(comptrollerAddressString); export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000'); diff --git a/subgraphs/venus/src/constants/config-template b/subgraphs/venus/src/constants/config-template new file mode 100644 index 00000000..d5af8f52 --- /dev/null +++ b/subgraphs/venus/src/constants/config-template @@ -0,0 +1,4 @@ +// Use yarn prepare commands to generate config typescript file per env + +export const vBnbAddress = '{{ vBnbAddress }}'; +export const comptrollerAddress = '{{ comptrollerAddress }}'; diff --git a/subgraphs/venus/src/mappings/comptroller.ts b/subgraphs/venus/src/mappings/comptroller.ts index f599f61a..fbe0cfca 100644 --- a/subgraphs/venus/src/mappings/comptroller.ts +++ b/subgraphs/venus/src/mappings/comptroller.ts @@ -19,15 +19,15 @@ import { getOrCreateComptroller } from '../operations/getOrCreate'; import { updateCommonVTokenStats } from '../operations/update'; import { ensureComptrollerSynced } from '../utilities'; -export const handleMarketListed = (event: MarketListed): void => { +export function handleMarketListed(event: MarketListed): void { // Dynamically index all new listed tokens VToken.create(event.params.vToken); // Create the market for this token, since it's now been listed. let market = createMarket(event.params.vToken.toHexString()); market.save(); -}; +} -export const handleMarketEntered = (event: MarketEntered): void => { +export function handleMarketEntered(event: MarketEntered): void { let market = Market.load(event.params.vToken.toHexString()); // Null check needed to avoid crashing on a new market added. Ideally when dynamic data // sources can source from the contract creation block and not the time the @@ -60,9 +60,9 @@ export const handleMarketEntered = (event: MarketEntered): void => { ); vTokenStats.enteredMarket = true; vTokenStats.save(); -}; +} -export const handleMarketExited = (event: MarketExited): void => { +export function handleMarketExited(event: MarketExited): void { let market = Market.load(event.params.vToken.toHexString()); // Null check needed to avoid crashing on a new market added. Ideally when dynamic data // sources can source from the contract creation block and not the time the @@ -95,15 +95,15 @@ export const handleMarketExited = (event: MarketExited): void => { ); vTokenStats.enteredMarket = false; vTokenStats.save(); -}; +} -export const handleNewCloseFactor = (event: NewCloseFactor): void => { +export function handleNewCloseFactor(event: NewCloseFactor): void { const comptroller = getOrCreateComptroller(); comptroller.closeFactor = event.params.newCloseFactorMantissa; comptroller.save(); -}; +} -export const handleNewCollateralFactor = (event: NewCollateralFactor): void => { +export function handleNewCollateralFactor(event: NewCollateralFactor): void { let market = Market.load(event.params.vToken.toHexString()); // Null check needed to avoid crashing on a new market added. Ideally when dynamic data // sources can source from the contract creation block and not the time the @@ -112,20 +112,20 @@ export const handleNewCollateralFactor = (event: NewCollateralFactor): void => { market.collateralFactorMantissa = event.params.newCollateralFactorMantissa; market.save(); } -}; +} // This should be the first event acccording to bscscan but it isn't.... price oracle is. weird -export const handleNewLiquidationIncentive = (event: NewLiquidationIncentive): void => { +export function handleNewLiquidationIncentive(event: NewLiquidationIncentive): void { const comptroller = getOrCreateComptroller(); comptroller.liquidationIncentive = event.params.newLiquidationIncentiveMantissa; comptroller.save(); -}; +} -export const handleNewPriceOracle = (event: NewPriceOracle): void => { +export function handleNewPriceOracle(event: NewPriceOracle): void { const comptroller = getOrCreateComptroller(); comptroller.priceOracle = event.params.newPriceOracle; comptroller.save(); -}; +} // Also handles DistributedBorrowerVenus with same signature export function handleXvsDistributed(event: DistributedSupplierVenus): void { diff --git a/subgraphs/venus/template.yaml b/subgraphs/venus/template.yaml index 58c94338..a905f6d5 100644 --- a/subgraphs/venus/template.yaml +++ b/subgraphs/venus/template.yaml @@ -8,7 +8,7 @@ dataSources: name: Comptroller network: {{ network }} source: - address: "{{ address }}" + address: "{{ comptrollerAddress }}" abi: Comptroller startBlock: {{ startBlock }} mapping: diff --git a/subgraphs/venus/tests/Comptroller.test.ts b/subgraphs/venus/tests/Comptroller.test.ts index 85b2d82d..c6848fce 100644 --- a/subgraphs/venus/tests/Comptroller.test.ts +++ b/subgraphs/venus/tests/Comptroller.test.ts @@ -8,13 +8,9 @@ import { test, } from 'matchstick-as/assembly/index'; -import { - comptrollerAddress, - interestRateModelAddress, - nullAddress, - vBnbAddress, -} from '../src/constants/addresses'; +import { comptrollerAddress, nullAddress, vBnbAddress } from '../src/constants/addresses'; import { handleMarketListed } from '../src/mappings/comptroller'; +import { interestRateModelAddress } from './constants'; import { createMarketListedEvent } from './events'; import { createComptrollerMock, createVBep20AndUnderlyingMock } from './mocks'; diff --git a/subgraphs/venus/tests/constants/index.ts b/subgraphs/venus/tests/constants/index.ts new file mode 100644 index 00000000..1415b0de --- /dev/null +++ b/subgraphs/venus/tests/constants/index.ts @@ -0,0 +1,5 @@ +import { Address } from '@graphprotocol/graph-ts'; + +export const interestRateModelAddress = Address.fromString( + '0x594942C0e62eC577889777424CD367545C796A74', +); diff --git a/yarn.lock b/yarn.lock index 9baeb27e..8f90eac8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6548,12 +6548,6 @@ __metadata: languageName: node linkType: hard -"core-pool-abis@workspace:packages/core-pool-abis": - version: 0.0.0-use.local - resolution: "core-pool-abis@workspace:packages/core-pool-abis" - languageName: unknown - linkType: soft - "core-util-is@npm:1.0.2": version: 1.0.2 resolution: "core-util-is@npm:1.0.2" From 2e3fb45c365d046e93c4fdd01ee088fa69e7617c Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Tue, 14 Nov 2023 12:25:35 -0300 Subject: [PATCH 2/6] fix: fix token event schemas; use addresses to identify tokens --- subgraphs/venus/schema.graphql | 30 ++++++++++++-------------- subgraphs/venus/src/mappings/vToken.ts | 14 +++++------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/subgraphs/venus/schema.graphql b/subgraphs/venus/schema.graphql index 7d32796b..03b86e29 100644 --- a/subgraphs/venus/schema.graphql +++ b/subgraphs/venus/schema.graphql @@ -156,7 +156,7 @@ interface VTokenTransfer { "Transaction hash concatenated with log index" id: ID! "vTokens transferred" - amount: BigDecimal! + amountMantissa: BigInt! "Account that received tokens" to: Bytes! "Account that sent tokens" @@ -165,8 +165,6 @@ interface VTokenTransfer { blockNumber: Int! "Block time" blockTime: Int! - "Symbol of the vToken transferred" - vTokenSymbol: String! } """ @@ -186,8 +184,8 @@ type TransferEvent implements VTokenTransfer @entity { blockNumber: Int! "Block time" blockTime: Int! - "Symbol of the vToken transferred" - vTokenSymbol: String! + "Address of the vToken transferred" + vTokenAddress: Bytes! } """ @@ -207,7 +205,7 @@ type MintEvent implements VTokenTransfer @entity { blockNumber: Int! "Block time" blockTime: Int! - "Address of the vToken transferred" + "Address of the vToken minted" vTokenAddress: Bytes! "Underlying token amount transferred" underlyingAmountMantissa: BigInt! @@ -253,10 +251,10 @@ type LiquidationEvent implements VTokenTransfer @entity { blockNumber: Int! "Block time" blockTime: Int! - "vToken that was sezied as collateral" - vTokenSymbol: String! - "Symbol of the underlying asset repaid through liquidation" - underlyingSymbol: String! + "Address of the vToken that was seized as collateral" + vTokenCollateralAddress: Bytes! + "Address of the underlying asset repaid through liquidation" + underlyingRepaidAddress: Bytes! "Underlying vToken amount that was repaid by liquidator" underlyingRepayAmountMantissa: BigInt! } @@ -278,8 +276,8 @@ interface UnderlyingTransfer { blockNumber: Int! "Block time" blockTime: Int! - "Symbol of the borrowed underlying asset" - underlyingSymbol: String! + "Address of the underlying token that was seized as transferred" + underlyingAddress: Bytes! } """ @@ -298,8 +296,8 @@ type BorrowEvent implements UnderlyingTransfer @entity { blockNumber: Int! "Block time" blockTime: Int! - "Symbol of the borrowed underlying asset" - underlyingSymbol: String! + "Address of the underlying token that was borrowed" + underlyingAddress: Bytes! } """ @@ -319,8 +317,8 @@ type RepayEvent implements UnderlyingTransfer @entity { blockNumber: Int! "Block time" blockTime: Int! - "Symbol of the borrowed underlying asset" - underlyingSymbol: String! + "Address of the underlying token that was repaid" + underlyingAddress: Bytes! "Payer of the borrow funds" payer: Bytes! } diff --git a/subgraphs/venus/src/mappings/vToken.ts b/subgraphs/venus/src/mappings/vToken.ts index e095b0a0..79137061 100644 --- a/subgraphs/venus/src/mappings/vToken.ts +++ b/subgraphs/venus/src/mappings/vToken.ts @@ -161,7 +161,7 @@ export const handleBorrow = (event: Borrow): void => { borrow.borrower = event.params.borrower; borrow.blockNumber = event.block.number.toI32(); borrow.blockTime = event.block.timestamp.toI32(); - borrow.underlyingSymbol = market.underlyingSymbol; + borrow.underlyingAddress = market.underlyingAddress; borrow.save(); if (event.params.accountBorrows == event.params.borrowAmount) { @@ -228,7 +228,7 @@ export const handleRepayBorrow = (event: RepayBorrow): void => { repay.borrower = event.params.borrower; repay.blockNumber = event.block.number.toI32(); repay.blockTime = event.block.timestamp.toI32(); - repay.underlyingSymbol = market.underlyingSymbol; + repay.underlyingAddress = market.underlyingAddress; repay.payer = event.params.payer; repay.save(); @@ -285,10 +285,6 @@ export const handleLiquidateBorrow = (event: LiquidateBorrow): void => { if (!marketRepayToken) { marketRepayToken = createMarket(event.address.toHexString()); } - let marketVTokenLiquidated = Market.load(event.params.vTokenCollateral.toHexString()); - if (!marketVTokenLiquidated) { - marketVTokenLiquidated = createMarket(event.params.vTokenCollateral.toHexString()); - } let mintID = event.transaction.hash .toHexString() .concat('-') @@ -300,9 +296,9 @@ export const handleLiquidateBorrow = (event: LiquidateBorrow): void => { liquidation.from = event.params.borrower; liquidation.blockNumber = event.block.number.toI32(); liquidation.blockTime = event.block.timestamp.toI32(); - liquidation.underlyingSymbol = marketRepayToken.underlyingSymbol; + liquidation.underlyingRepaidAddress = marketRepayToken.underlyingAddress; liquidation.underlyingRepayAmountMantissa = event.params.repayAmount; - liquidation.vTokenSymbol = marketVTokenLiquidated.symbol; + liquidation.vTokenCollateralAddress = event.params.vTokenCollateral; liquidation.save(); }; @@ -407,7 +403,7 @@ export const handleTransfer = (event: Transfer): void => { transfer.from = event.params.from; transfer.blockNumber = event.block.number.toI32(); transfer.blockTime = event.block.timestamp.toI32(); - transfer.vTokenSymbol = market.symbol; + transfer.vTokenAddress = event.address; transfer.save(); }; From 81b7fcf7a0692bdca0685e484a9658a69b284910 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Tue, 14 Nov 2023 14:22:24 -0300 Subject: [PATCH 3/6] refactor: remove VBep20Storage abi --- subgraphs/venus/src/operations/create.ts | 4 +--- subgraphs/venus/template.yaml | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/subgraphs/venus/src/operations/create.ts b/subgraphs/venus/src/operations/create.ts index 5c79e661..5807a172 100644 --- a/subgraphs/venus/src/operations/create.ts +++ b/subgraphs/venus/src/operations/create.ts @@ -2,7 +2,6 @@ import { Address, BigInt, log } from '@graphprotocol/graph-ts'; import { Account, AccountVToken, Market, MintEvent, RedeemEvent } from '../../generated/schema'; import { BEP20 } from '../../generated/templates/VToken/BEP20'; -import { VBep20Storage } from '../../generated/templates/VToken/VBep20Storage'; import { VToken } from '../../generated/templates/VToken/VToken'; import { zeroBigInt32 } from '../constants'; import { nullAddress, vBnbAddress } from '../constants/addresses'; @@ -46,7 +45,6 @@ export function createAccount(accountId: string): Account { export function createMarket(marketAddress: string): Market { let market: Market; const contract = VToken.bind(Address.fromString(marketAddress)); - const marketBep20Storage = VBep20Storage.bind(Address.fromString(marketAddress)); log.debug('[createMarket] market address: {}', [marketAddress]); @@ -61,7 +59,7 @@ export function createMarket(marketAddress: string): Market { // It is all other VBEP20 contracts } else { market = new Market(marketAddress); - market.underlyingAddress = marketBep20Storage.underlying(); + market.underlyingAddress = contract.underlying(); log.debug('[createMarket] market underlying address: {}', [ market.underlyingAddress.toHexString(), ]); diff --git a/subgraphs/venus/template.yaml b/subgraphs/venus/template.yaml index a905f6d5..ea72690d 100644 --- a/subgraphs/venus/template.yaml +++ b/subgraphs/venus/template.yaml @@ -65,8 +65,6 @@ templates: abis: - name: VToken file: ../../node_modules/@venusprotocol/venus-protocol-orig-events/artifacts/contracts/Tokens/VTokens/VBep20.sol/VBep20.json - - name: VBep20Storage - file: ../../node_modules/@venusprotocol/venus-protocol-orig-events/artifacts/contracts/Tokens/VTokens/VTokenInterfaces.sol/VBep20Storage.json - name: PriceOracle file: ../../node_modules/@venusprotocol/oracle/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json - name: BEP20 @@ -111,8 +109,6 @@ templates: abis: - name: VTokenUpdatedEvents file: ../../node_modules/@venusprotocol/venus-protocol/artifacts/contracts/Tokens/VTokens/VBep20.sol/VBep20.json - - name: VBep20Storage - file: ../../node_modules/@venusprotocol/venus-protocol/artifacts/contracts/Tokens/VTokens/VTokenInterfaces.sol/VBep20Storage.json eventHandlers: - event: Mint(address,uint256,uint256,uint256) handler: handleMint From 61099ca69717c8acf39ca0529f5fa0b5730e3055 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Tue, 14 Nov 2023 14:22:45 -0300 Subject: [PATCH 4/6] fix: remove debug flags from isolated pool subgraph deploy command --- subgraphs/isolated-pools/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subgraphs/isolated-pools/package.json b/subgraphs/isolated-pools/package.json index 816f0a42..e1f7e5b6 100644 --- a/subgraphs/isolated-pools/package.json +++ b/subgraphs/isolated-pools/package.json @@ -16,8 +16,8 @@ "build:bsc": "graph build --ipfs https://api.thegraph.com/ipfs/ ", "deploy:integration": "graph deploy venusprotocol/venus-isolated-pools --ipfs http://localhost:5001 --node http://127.0.0.1:8020/", "deploy:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml && npx mustache config/docker.json src/constants/config-template > src/constants/config.ts && npx graph deploy venusprotocol/venus-isolated-pools --ipfs http://ipfs:5001 --node http://graph-node:8020/ --version-label ci", - "deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-isolated-pools-chapel --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-isolated-pools --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-isolated-pools-chapel --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-isolated-pools --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", "prepare:docker": "npx mustache config/docker.json template.yaml > subgraph.yaml && npx mustache config/docker.json src/constants/config-template > src/constants/config.ts", "prepare:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts", "prepare:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts", From 34206c92ebedb1cba1d90bb1b6729a00f13070ab Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Tue, 14 Nov 2023 14:27:08 -0300 Subject: [PATCH 5/6] fix: use function declarations for handlers --- subgraphs/venus/src/mappings/vToken.ts | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/subgraphs/venus/src/mappings/vToken.ts b/subgraphs/venus/src/mappings/vToken.ts index 79137061..a0f6ea6e 100644 --- a/subgraphs/venus/src/mappings/vToken.ts +++ b/subgraphs/venus/src/mappings/vToken.ts @@ -53,7 +53,7 @@ import { getMarketId, getTransactionId } from '../utilities/ids'; * No need to updateCommonVTokenStats, handleTransfer() will * No need to update vTokenBalance, handleTransfer() will */ -export const handleMint = (event: Mint): void => { +export function handleMint(event: Mint): void { let market = Market.load(event.address.toHexString()); if (!market) { market = createMarket(event.address.toHexString()); @@ -65,9 +65,9 @@ export const handleMint = (event: Mint): void => { market.supplierCount = market.supplierCount.plus(oneBigInt); market.save(); } -}; +} -export const handleMintBehalf = (event: MintBehalf): void => { +export function handleMintBehalf(event: MintBehalf): void { let market = Market.load(event.address.toHexString()); if (!market) { market = createMarket(event.address.toHexString()); @@ -79,7 +79,7 @@ export const handleMintBehalf = (event: MintBehalf): void => { market.supplierCount = market.supplierCount.plus(oneBigInt); market.save(); } -}; +} /* Account supplies vTokens into market and receives underlying asset in exchange * @@ -93,7 +93,7 @@ export const handleMintBehalf = (event: MintBehalf): void => { * No need to updateCommonVTokenStats, handleTransfer() will * No need to update vTokenBalance, handleTransfer() will */ -export const handleRedeem = (event: Redeem): void => { +export function handleRedeem(event: Redeem): void { let market = Market.load(event.address.toHexString()); if (!market) { market = createMarket(event.address.toHexString()); @@ -106,7 +106,7 @@ export const handleRedeem = (event: Redeem): void => { market.supplierCount = market.supplierCount.minus(oneBigInt); market.save(); } -}; +} /* Borrow assets from the protocol. All values either BNB or BEP20 * @@ -117,7 +117,7 @@ export const handleRedeem = (event: Redeem): void => { * Notes * No need to updateMarket(), handleAccrueInterest() ALWAYS runs before this */ -export const handleBorrow = (event: Borrow): void => { +export function handleBorrow(event: Borrow): void { let market = Market.load(event.address.toHexString()); if (!market) { market = createMarket(event.address.toHexString()); @@ -170,7 +170,7 @@ export const handleBorrow = (event: Borrow): void => { market.borrowerCountAdjusted = market.borrowerCountAdjusted.plus(oneBigInt); market.save(); } -}; +} /* Repay some amount borrowed. Anyone can repay anyones balance * @@ -186,7 +186,7 @@ export const handleBorrow = (event: Borrow): void => { * markets value. We keep this, even though you might think it would reset to 0 upon full * repay. */ -export const handleRepayBorrow = (event: RepayBorrow): void => { +export function handleRepayBorrow(event: RepayBorrow): void { let market = Market.load(event.address.toHexString()); if (!market) { market = createMarket(event.address.toHexString()); @@ -242,7 +242,7 @@ export const handleRepayBorrow = (event: RepayBorrow): void => { market.borrowerCountAdjusted = market.borrowerCountAdjusted.minus(oneBigInt); market.save(); } -}; +} /* * Liquidate an account who has fell below the collateral factor. @@ -260,7 +260,7 @@ export const handleRepayBorrow = (event: RepayBorrow): void => { * of the vTokens, which is covered by transfer. Therefore we only * add liquidation counts in this handler. */ -export const handleLiquidateBorrow = (event: LiquidateBorrow): void => { +export function handleLiquidateBorrow(event: LiquidateBorrow): void { let liquidatorID = event.params.liquidator.toHex(); let liquidator = Account.load(liquidatorID); if (liquidator == null) { @@ -300,7 +300,7 @@ export const handleLiquidateBorrow = (event: LiquidateBorrow): void => { liquidation.underlyingRepayAmountMantissa = event.params.repayAmount; liquidation.vTokenCollateralAddress = event.params.vTokenCollateral; liquidation.save(); -}; +} /* Transferring of vTokens * @@ -317,7 +317,7 @@ export const handleLiquidateBorrow = (event: LiquidateBorrow): void => { * This const handles all 4 cases. Transfer is emitted alongside the mint, redeem, and seize * events. So for those events, we do not update vToken balances. */ -export const handleTransfer = (event: Transfer): void => { +export function handleTransfer(event: Transfer): void { // We only updateMarket() if accrual block number is not up to date. This will only happen // with normal transfers, since mint, redeem, and seize transfers will already run updateMarket() let marketId = getMarketId(event.address); @@ -405,13 +405,13 @@ export const handleTransfer = (event: Transfer): void => { transfer.blockTime = event.block.timestamp.toI32(); transfer.vTokenAddress = event.address; transfer.save(); -}; +} export function handleAccrueInterest(event: AccrueInterest): void { updateMarket(event.address, event.block.number.toI32(), event.block.timestamp.toI32()); } -export const handleNewReserveFactor = (event: NewReserveFactor): void => { +export function handleNewReserveFactor(event: NewReserveFactor): void { let marketID = event.address.toHex(); let market = Market.load(marketID); if (!market) { @@ -419,7 +419,7 @@ export const handleNewReserveFactor = (event: NewReserveFactor): void => { } market.reserveFactor = event.params.newReserveFactorMantissa; market.save(); -}; +} export function handleNewMarketInterestRateModel(event: NewMarketInterestRateModel): void { let marketID = event.address.toHex(); From dd5155d25d663c1e822a32b4714a84dd3931e5d8 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Wed, 15 Nov 2023 17:43:59 -0300 Subject: [PATCH 6/6] fix: dont cast bigint to hex --- subgraphs/venus/src/mappings/comptroller.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/subgraphs/venus/src/mappings/comptroller.ts b/subgraphs/venus/src/mappings/comptroller.ts index fbe0cfca..7f71a962 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 { BigInt, log } from '@graphprotocol/graph-ts'; +import { log } from '@graphprotocol/graph-ts'; import { DistributedSupplierVenus, @@ -130,12 +130,10 @@ export function handleNewPriceOracle(event: NewPriceOracle): void { // Also handles DistributedBorrowerVenus with same signature export function handleXvsDistributed(event: DistributedSupplierVenus): void { let vTokenAddress = event.params.vToken.toHex(); - let venusDelta = event.params.venusDelta.toHex(); + const venusDelta = event.params.venusDelta; let market = Market.load(vTokenAddress); if (market == null) { market = createMarket(vTokenAddress); } - market.totalXvsDistributedMantissa = market.totalXvsDistributedMantissa.plus( - BigInt.fromString(venusDelta), - ); + market.totalXvsDistributedMantissa = market.totalXvsDistributedMantissa.plus(venusDelta); }