Skip to content

Commit

Permalink
feat: add totalXvsDistributedWei to market
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Sep 4, 2023
1 parent 88f57e0 commit 3602e27
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions subgraphs/venus/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type Market @entity {
underlyingPriceUSD: BigDecimal!
"Underlying token decimal length"
underlyingDecimals: Int!
"Total XVS Distributed for this market"
totalXvsDistributedMantissa: BigInt!
}

"""
Expand Down
3 changes: 3 additions & 0 deletions subgraphs/venus/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { BigInt } from '@graphprotocol/graph-ts';

export const zeroBigInt32 = BigInt.fromString('0');
16 changes: 15 additions & 1 deletion subgraphs/venus/src/mappings/comptroller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable prefer-const */
// to satisfy AS compiler
import { log } from '@graphprotocol/graph-ts';
import { BigInt, log } from '@graphprotocol/graph-ts';

import {
DistributedSupplierVenus,
MarketEntered,
MarketExited,
MarketListed,
Expand Down Expand Up @@ -128,3 +129,16 @@ export const handleNewPriceOracle = (event: NewPriceOracle): void => {
comptroller.priceOracle = event.params.newPriceOracle;
comptroller.save();
};

// Also handles DistributedBorrowerVenus with same signature
export function handleXvsDistributed(event: DistributedSupplierVenus): void {
let vTokenAddress = event.params.vToken.toHex();
let venusDelta = event.params.venusDelta.toHex();
let market = Market.load(vTokenAddress);
if (market == null) {
market = createMarket(vTokenAddress);
}
market.totalXvsDistributedMantissa = market.totalXvsDistributedMantissa.plus(
BigInt.fromString(venusDelta),
);
}
2 changes: 2 additions & 0 deletions subgraphs/venus/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Address, BigDecimal, BigInt, log } from '@graphprotocol/graph-ts';
import { Account, AccountVToken, Market } from '../../generated/schema';
import { BEP20 } from '../../generated/templates/VToken/BEP20';
import { VToken } from '../../generated/templates/VToken/VToken';
import { zeroBigInt32 } from '../constants';
import { nullAddress, vBnbAddress } from '../constants/addresses';
import { zeroBD } from '../utilities/exponentToBigDecimal';
import { getUnderlyingPrice } from '../utilities/getUnderlyingPrice';
Expand Down Expand Up @@ -96,6 +97,7 @@ export const createMarket = (marketAddress: string): Market => {
market.blockTimestamp = 0;
market.borrowIndex = zeroBD;
market.reserveFactor = reserveFactor.reverted ? BigInt.fromI32(0) : reserveFactor.value;
market.totalXvsDistributedMantissa = zeroBigInt32;

return market;
};
4 changes: 4 additions & 0 deletions subgraphs/venus/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ dataSources:
handler: handleNewLiquidationIncentive
- event: NewPriceOracle(address,address)
handler: handleNewPriceOracle
- event: DistributedBorrowerVenus(indexed address,indexed address,uint256,uint256)
handler: handleXvsDistributed
- event: DistributedSupplierVenus(indexed address,indexed address,uint256,uint256)
handler: handleXvsDistributed
templates:
- name: VToken
kind: ethereum/contract
Expand Down

0 comments on commit 3602e27

Please sign in to comment.